Login page in jsp

Here we give an example of login page using jsp. There are two jsp file one is login.jsp and another is loginsubmit.jsp. you can see the both file as below:

login.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Example</title>
</head>
<body>
<form name="loginform" action="loginsubmit.jsp" method="post">
<table width="400" align="center">
<tr><td colspan="2"><a href="http://www.javaforecast4u.com"><h2>Welcome to Java Forecast 4u</h2></a></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td colspan="2" align="center"><h3>User Login</h3></td> </tr>
<tr>
<td>User Id:</td>
<td><input name="userid" type="text"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password"/></td>
</tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="Login"></td> </tr>
</table>
</form>
</body>
</html>

another file is 

loginsubmit.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Example</title>
</head>
<body>
<%
String userid=request.getParameter("userid");
String password=request.getParameter("password");
if(userid.equals(password))
{%>
<table width="400" align="center">
<tr><td>Welcome:<%out.println(userid); %></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><font color="green" size="5" >You are login successfully</font></td></tr>

</table>
<%
}
else
{
       %>
       <table width="400" align="center">
       <tr><td></td></tr>
       <tr><td></td></tr>
       <tr><td></td></tr>
       <tr><td><font color="red" size="4" >Sorry Your user Id and password don't match!</font></td></tr>
       <tr><td></td></tr>
       <tr><td></td></tr>
       <tr><td><a href="login.jsp"><h4>Try Again</h4></a></td></tr>
       </table>
       <%    
}
%>

</body>
</html>

Output:






















You can give the userid:username and password:username same then you get following result:























You give the wrong userid and password then you will get following result:















1 comment :