jsp注册表单错误 [英] Error in jsp registration form
问题描述
作为jsp技术的新手。
如何在jsp中比较密码和确认密码而不用javascript。
我在申请表上张贴代码jsp。
1)。 SignIn logic.jsp
<% -
文档:SignInlogic
创建日期:2017年7月25日,9 :58:57 AM
作者:ttkau
- %>
<%@ page contentType =text / htmlpageEncoding =UTF-8%>
<!DOCTYPE html>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>< / title>
< / head>
< body>
<%@ page import =java.sql。*; %GT;
<%
response.setContentType(text / css);
连接con = null;
语句stmt = null;
ResultSet rs = null;
final String Db_User =root;
final String Db_pass =pitech2017;
final String db_url =jdbc:mysql // localhost:3306 / registration;
final String jdbc_url =com.mysql.jdbc.Driver;
String user_Name = request.getParameter(txtName);
String pass_code = request.getParameter(txtpass);
try {
Class.forName(jdbc_url);
con = DriverManager.getConnection(db_url,Db_User,Db_pass);
字符串login_query =选择名称,来自注册的密码,其中name ='+ user_Name +'和password ='+ pass_code +';
stmt = con.createStatement();
if(rs.next())
{
String user = rs.getString(name);
String passw = rs.getString(password);
String e_maill = rs.getString(email);
if(user_Name.equals(user)&& pass_code.equals(passw))
{
out.println(< a href ='welcome.jsp'> Welcome< ; / A>中);
out.println(welcome+ e_maill);
}
}
} catch(例外e){
e.printStackTrace();
}
%>
< / body>
< / html>
2) SignupLogic.jsp
response.setContentType(text / html);
PreparedStatement ps = null;
语句st = null;
ResultSet rs = null;
字符串名称,邮件,mobile_no,密码,confirm_pass;
// String value1,value2;
final String jdbc_url =com.mysql.jdbc.Driver;
final String Db_User =root;
final String Db_pass =pitech2017;
final String db_url =jdbc:mysql // localhost:3306 / register;
name = request.getParameter(txtname);
mail = request.getParameter(txtEmail);
mobile_no = request.getParameter(txtmobile);
password = request.getParameter(txtpassword);
confirm_pass = request.getParameter(txtconfirmpassword);
try
{
Class.forName(jdbc_url);
Connection connect = DriverManager.getConnection(db_url,Db_User,Db_pass);
out.println(建立连接);
st = connect.createStatement();
rs = st.executeQuery(从注册中选择名称,其中name ='+ name);
boolean flag = false;
while(rs.next())
{
if(name.equals(rs.getString(1)))
{
flag = true;
out.println(< a href ='error.html'>再次注册!< / a>);
}
else
{
字符串查询=插入注册(名称,电子邮件,mobileNo,密码,confirmPass)值(?,?,?,?,?) ;
connect = DriverManager.getConnection(db_url,Db_User,Db_pass);
ps = connect.prepareStatement(query);
ps.setString(1,name);
ps.setString(2,mail);
ps.setString(3,mobile_no);
ps.setString(4,密码);
ps.setString(5,confirm_pass);
if(password.equals(confirm_pass))
{
ps.executeUpdate();
out.println(用户已注册);
out.println(< a href ='SignIn.jsp'> Login<);
}
其他
out.println(< a href ='error.html'>密码不匹配< / a>);
}
}
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
%>
< / body>
< / html>
3)Register.jsp
<% -
文件:注册
创建时间:2017年7月24日上午11:48:15
作者:ttkau
- %>
<%@ page contentType =text / htmlpageEncoding =UTF-8%>
<!DOCTYPE html>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>注册< / title>
< / head>
< body>
< form action =SignUpLogic.jspmethod =post>
< h1>< center> 注册< / center> < / h1>
< Center>
< table style =width:50%>
< tr>
< th>< / th>
< / tr>
< tr>
< td>输入姓名< / td>
< td>< input type =textname =txtnamerequired =required/>< / td>
< / tr>
< tr>
< td>电子邮件< / td>
< td>< input type =textname =txtEmailrequired =requiredpattern =[a-z0-9 ._%+ - ] + @ [a-z0-9。 - ] + \ [AZ] {2,3} $>。< / TD>
< / tr>
< tr>
< td>移动电话号码< / td>
< td>< input type =textname =txtmobilerequired =requiredpattern ='^ \ +?\d {0,12}'/> < / TD>
< / tr>
< tr>
< td>密码< / td>
< td>< input type =passwordname =txtpasswordrequired =required/>< / td>
< / tr>
< tr>
< td>确认密码< / td>
< td>< input type =passwordname =txtconfirmpasswordrequired =required/>< / td>< / tr>
< tr>
< td colspan =3>
< input type =submitvalue =Register/>
< / td>
< / tr>
< / table>
< / center>
< / form>
< / body>
< / html>
4)。 SignIN.jsp
<% -
文件:SignIn
创建日期:2017年7月24日,1 :39:00 PM
作者:ttkau
- %>
<%@ page contentType =text / htmlpageEncoding =UTF-8%>
<!DOCTYPE html>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title> JSP页< / title>
< / head>
< body>
< form action =SignInlogic.jspmethod =post>
< center>
< table style =width:50%;>
< tr>
< td>
< input type =textname =txtNameplaceholder =输入useramerequired =required/>
< / td>
< / tr>
< tr>
< td>
< input type =passwordname =txtpassplaceholder =输入密码required =required/>
< / td>
< / tr>
< tr>
< td>
< input type =submitvalue =登录/>
< / td>
< / tr>
< / table>
< / center>
< / form>
< / body>运行此网络项目后
< / html>
:
执行注册页面时,没有插入数据的结果。
当我们执行signIn页面时显示无法编译的源代码java文件
我尝试过的事情:
我还没有尝试过任何新的东西,如jsp
>< / td>
< / tr>
< tr>
< td>手机号< / td>
< td>< input type =textname =txtmobilerequired =requiredpattern ='^ \ +?\d {0,12}'/>< / td>
< / tr>
< tr>
< td>密码< / td>
< td><输入类型=密码名称=txtpasswordrequired =required/>< / td>
< / TR>
< tr>
< td>确认密码< / td>
< td>< input type =passwordname =txtconfirmpasswordrequired =required/>< / td>< / tr>
< tr>
< td colspan =3>
< input type =submitvalue =Register/>
< / td>
< / tr>
< / table>
< / center>
< / form>
< / body>
< / html>
4)。 SignIN.jsp
<% -
文件:SignIn
创建日期:2017年7月24日,1 :39:00 PM
作者:ttkau
- %>
<%@ page contentType =text / htmlpageEncoding =UTF-8%>
<!DOCTYPE html>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title> JSP页< / title>
< / head>
< body>
< form action =SignInlogic.jspmethod =post>
< center>
< table style =width:50%;>
< tr>
< td>
< input type =textname =txtNameplaceholder =输入useramerequired =required/>
< / td>
< / tr>
< tr>
< td>
< input type =passwordname =txtpassplaceholder =输入密码required =required/>
< / td>
< / tr>
< tr>
< td>
< input type =submitvalue =登录/>
< / td>
< / tr>
< / table>
< / center>
< / form>
< / body>运行此网络项目后
< / html>
:
执行注册页面时,没有插入数据的结果。
当我们执行signIn页面时显示无法编译的源代码java文件
我尝试了什么:
我还没有尝试过任何新的东西,如jsp
sir ! i have written online registration form in jsp !
as i m new to jsp technology .
how i can compare password and confirm password in jsp without javascript.
I m posting code jsp for application form.
1). SignIn logic.jsp
<%-- Document : SignInlogic Created on : 25 Jul, 2017, 9:58:57 AM Author : ttkau --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <%@page import="java.sql.*;" %> <% response.setContentType("text/css"); Connection con = null; Statement stmt = null; ResultSet rs = null; final String Db_User="root"; final String Db_pass="pitech2017"; final String db_url="jdbc:mysql//localhost:3306/registration"; final String jdbc_url="com.mysql.jdbc.Driver"; String user_Name = request.getParameter("txtName"); String pass_code = request.getParameter("txtpass"); try { Class.forName(jdbc_url); con = DriverManager.getConnection(db_url,Db_User,Db_pass); String login_query = "select name,password from signup where name='"+user_Name +"' and password='"+pass_code+"'"; stmt = con.createStatement(); if(rs.next()) { String user = rs.getString("name"); String passw = rs.getString("password"); String e_maill = rs.getString("email"); if(user_Name.equals(user)&&pass_code.equals(passw)) { out.println("<a href='welcome.jsp'>Welcome</a>"); out.println("welcome"+e_maill); } } } catch (Exception e) { e.printStackTrace(); } %> </body> </html>
2) SignupLogic.jsp
response.setContentType("text/html"); PreparedStatement ps = null; Statement st= null; ResultSet rs = null; String name, mail,mobile_no,password,confirm_pass; // String value1,value2; final String jdbc_url="com.mysql.jdbc.Driver"; final String Db_User="root"; final String Db_pass="pitech2017"; final String db_url="jdbc:mysql//localhost:3306/register"; name = request.getParameter("txtname"); mail = request.getParameter("txtEmail"); mobile_no = request.getParameter("txtmobile"); password = request.getParameter("txtpassword"); confirm_pass = request.getParameter("txtconfirmpassword"); try { Class.forName(jdbc_url); Connection connect = DriverManager.getConnection(db_url,Db_User,Db_pass); out.println("Connection Established"); st = connect.createStatement(); rs = st.executeQuery("select name from signup where name='"+name); boolean flag= false; while(rs.next()) { if(name.equals(rs.getString(1))) { flag = true; out.println("<a href='error.html'>Register Again!</a>"); } else { String query = "insert into signup(name,email,mobileNo,password,confirmPass) values(?,?,?,?,?)"; connect = DriverManager.getConnection(db_url,Db_User,Db_pass); ps = connect.prepareStatement(query); ps.setString(1, name); ps.setString(2, mail); ps.setString(3, mobile_no); ps.setString(4, password); ps.setString(5, confirm_pass); if(password.equals(confirm_pass)) { ps.executeUpdate(); out.println("User is registered"); out.println("<a href='SignIn.jsp'>Login<"); } else out.println("<a href='error.html'>Passwords does not match</a>"); } } } catch(ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } %> </body> </html>
3)Register.jsp
<%-- Document : Register Created on : 24 Jul, 2017, 11:48:15 AM Author : ttkau --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Registration</title> </head> <body> <form action="SignUpLogic.jsp" method="post"> <h1><center>Registration</center></h1> <Center> <table style="width: 50%"> <tr> <th></th> </tr> <tr> <td>Enter Name</td> <td><input type="text" name="txtname" required="required"/></td> </tr> <tr> <td>Email</td> <td><input type="text" name="txtEmail" required="required" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"></td> </tr> <tr> <td>Mobile No.</td> <td><input type="text" name="txtmobile" required="required" pattern='^\+?\d{0,12}'/> </td> </tr> <tr> <td>Password</td> <td><input type="password" name="txtpassword" required="required"/></td> </tr> <tr> <td>Confirm Password</td> <td><input type="password" name="txtconfirmpassword" required="required"/></td></tr> <tr> <td colspan="3"> <input type="submit" value="Register"/> </td> </tr> </table> </center> </form> </body> </html>
4). SignIN.jsp
<%-- Document : SignIn Created on : 24 Jul, 2017, 1:39:00 PM Author : ttkau --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <form action="SignInlogic.jsp" method="post"> <center> <table style="width: 50%;"> <tr> <td> <input type="text" name="txtName" placeholder="Enter userame" required="required"/> </td> </tr> <tr> <td> <input type="password" name="txtpass" placeholder="Enter password" required="required"/> </td> </tr> <tr> <td> <input type="submit" value="Login"/> </td> </tr> </table> </center> </form> </body> </html>
after running this web project:
when signup page is executed , there is not result of inserting data.
when we execute signIn page it shows the uncompilable source code java file
What I have tried:
I have not tried yet anything as i m new to jsp
"></td> </tr> <tr> <td>Mobile No.</td> <td><input type="text" name="txtmobile" required="required" pattern='^\+?\d{0,12}'/> </td> </tr> <tr> <td>Password</td> <td><input type="password" name="txtpassword" required="required"/></td> </tr> <tr> <td>Confirm Password</td> <td><input type="password" name="txtconfirmpassword" required="required"/></td></tr> <tr> <td colspan="3"> <input type="submit" value="Register"/> </td> </tr> </table> </center> </form> </body> </html>
4). SignIN.jsp
<%-- Document : SignIn Created on : 24 Jul, 2017, 1:39:00 PM Author : ttkau --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <form action="SignInlogic.jsp" method="post"> <center> <table style="width: 50%;"> <tr> <td> <input type="text" name="txtName" placeholder="Enter userame" required="required"/> </td> </tr> <tr> <td> <input type="password" name="txtpass" placeholder="Enter password" required="required"/> </td> </tr> <tr> <td> <input type="submit" value="Login"/> </td> </tr> </table> </center> </form> </body> </html>
after running this web project:
when signup page is executed , there is not result of inserting data.
when we execute signIn page it shows the uncompilable source code java file
What I have tried:
I have not tried yet anything as i m new to jsp
这篇关于jsp注册表单错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!