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;
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