
how to create login page in jsp

Here is a jsp code that creates the login page and check whether the user is valid or not.
1)login.jsp:
<html> <form name="form" method="post" action="check.jsp"> <table> <tr><td>Username:</td><td><input type="text" name="user"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass"></td></tr> <tr><td></td><td><input type="submit" value="Login"></td></tr> </table> </form> </html>
2)check.jsp:
<%@page import="java.sql.*"%>
<%
try{
String user=request.getParameter("user");
String pass=request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from register where username='"+user+"' and password='"+pass+"'");
int count=0;
while(rs.next()){
count++;
}
if(count>0){
out.println("welcome "+user);
}
else{
response.sendRedirect("login.jsp");
}
}
catch(Exception e){
System.out.println(e);
}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.