Practical 4
c) Create a registration and login JSP application to
register and authenticate the user based on username
and password using JDBC.
[Link]
Enter Username:
Enter Password:
Re-Enter Password:
Enter Email:
Enter Country:
Reset Register
<html>
<form action="[Link]" >
Enter Username: <input type="text" name="t1"><br>
Enter Password: <input type="password" name="t2"><br>
Re-Enter Password: <input type="password" name="t3"><br>
Enter Email: <input type="text" name="t4"> <br>
Enter Country: <input type="text" name="t5"> <br>
<input type="reset"> <input type="submit" value="Register">
</form>
</html>
Creating a jsp page having name [Link]
[Link]
<%@page contentType="text/html" pageEncoding="UTF-8" import="[Link].*"%>
<html>
<body>
<%
String uname=[Link]("t1");
String pass1=[Link]("t2");
String pass2=[Link]("t3");
String email=[Link]("t4");
String country=[Link]("t5");
if([Link](pass2))
try
[Link]("[Link]");
Connection
con=[Link]("jdbc:mysql://localhost:3306/student1","admin"
,"nilam");
PreparedStatement pst=[Link]("insert into info values(?,?,?,?,?)");
[Link](1,uname);
[Link](2,pass1);
[Link](3,pass2);
[Link](4,email);
[Link](5,country);
int row=[Link]();
if(row==1)
[Link]("Registration successfully done......");
else
[Link]("Registration Failed.....");
%>
<jsp:include page="[Link]"></jsp:include>
<%
catch(Exception e)
[Link](e);
else
{
[Link]("Password Mismatch....");
%>
<jsp:include page="[Link]"></jsp:include>
<%
%>
</body>
</html>
[Link]
Enter Username:
Enter Password:
Reset login
<html>
<form action="[Link]">
Enter Username: <input type="text" name="t1"><br>
Enter Password: <input type="password" name="t2"><br>
<input type="reset"> <input type="submit" value="login">
</form>
</html>
Creating a servlet page having name [Link]
[Link]
<%@page contentType="text/html" import="[Link].*"%>
<!DOCTYPE html>
<html>
<body>
<%
String uname=[Link]("t1");
String pass1=[Link]("t2");
try
[Link]("[Link]");
Connection
con=[Link]("jdbc:mysql://localhost:3306/student1","admin"
,"nilam");
PreparedStatement pst=[Link]("select pass1 from info where
name=?");
[Link](1,uname);
ResultSet rs=[Link]();
if([Link]())
if([Link]([Link](1)))
[Link]("<h1> login Successfully!!!! </h1>");
}
else
[Link]("<h1> username does not exist..!!!! </h1>");
%> <jsp:include page="[Link]"></jsp:include>
<%
catch(Exception e)
[Link](e);
%>
</body>
</html>
Output