0% found this document useful (0 votes)
3 views8 pages

Practical 4

The document outlines the creation of a registration and login JSP application using JDBC for user authentication. It includes HTML forms for user registration and login, as well as JSP code for handling user input and database interactions. The application checks for password matches during registration and validates user credentials during login, providing appropriate feedback for each action.

Uploaded by

fannyskylark2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Practical 4

The document outlines the creation of a registration and login JSP application using JDBC for user authentication. It includes HTML forms for user registration and login, as well as JSP code for handling user input and database interactions. The application checks for password matches during registration and validates user credentials during login, providing appropriate feedback for each action.

Uploaded by

fannyskylark2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Practical 4

c) Create a registration and login JSP application to


register and authenticate the user based on username
and password using JDBC.

Index.html
Enter Username:
Enter Password:
Re-Enter Password:
Enter Email:
Enter Country:
Reset Register

<html>
<form action="reg.jsp" >
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 reg.jsp

reg.jsp

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>

<html>

<body>

<%

String uname=request.getParameter("t1");

String pass1=request.getParameter("t2");

String pass2=request.getParameter("t3");

String email=request.getParameter("t4");

String country=request.getParameter("t5");

if(pass1.equals(pass2))

try

Class.forName("com.mysql.jdbc.Driver");

Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student1","admin"
,"nilam");

PreparedStatement pst=con.prepareStatement("insert into info values(?,?,?,?,?)");

pst.setString(1,uname);

pst.setString(2,pass1);
pst.setString(3,pass2);

pst.setString(4,email);

pst.setString(5,country);

int row=pst.executeUpdate();

if(row==1)

out.println("Registration successfully done......");

else

out.println("Registration Failed.....");

%>

<jsp:include page="index.html"></jsp:include>

<%

catch(Exception e)

out.println(e);

else

{
out.println("Password Mismatch....");

%>

<jsp:include page="index.html"></jsp:include>

<%

%>

</body>

</html>

Login.html
Enter Username:
Enter Password:
Reset login

<html>

<form action="log.jsp">

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 log.java


log.java
<%@page contentType="text/html" import="java.sql.*"%>

<!DOCTYPE html>

<html>

<body>

<%

String uname=request.getParameter("t1");

String pass1=request.getParameter("t2");

try

Class.forName("com.mysql.jdbc.Driver");

Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student1","admin"
,"nilam");

PreparedStatement pst=con.prepareStatement("select pass1 from info where


name=?");

pst.setString(1,uname);

ResultSet rs=pst.executeQuery();

if(rs.next())

if(pass1.equals(rs.getString(1)))

out.println("<h1> login Successfully!!!! </h1>");


}

else

out.println("<h1> username does not exist..!!!! </h1>");

%> <jsp:include page="index.html"></jsp:include>

<%

catch(Exception e)

out.println(e);

%>

</body>

</html>

Output

You might also like