Login Form In JSP
Jsp_Login.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Login Page</title>
</head>
<body>
<form action="Check.jsp" method="get">
<table align="center">
<tr>
<td>
Username:
</td>
<td>
<input type="text" name="U_name" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="pwd" />
</td>
</tr>
<tr>
<td>
<input type="Submit" value="Login" />
</td>
</tr>
</table>
</form>
</body>
</html>
Check.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Check Page</title>
</head>
<body>
<%
try
{
String nm=request.getParameter("U_name");
String ps=request.getParameter("pwd");
if(nm.equals("") || ps.equals(""))
{
response.sendRedirect("Blank.jsp");
}
else if(nm.equals("Aditya") && ps.equals("password"))
{
response.sendRedirect("Welcome.jsp");
}
else
{
response.sendRedirect("Error_Page.jsp");
}
}
finally {
}
%>
</body>
</html>
Erorr.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Error Page</title>
</head>
<body>
<form action="Jsp_Login.jsp" method="get">
<h2>Either Username or Password is wrong</h2>
<input type="Submit" value="Go Back!!">
</input>
</form>
</body>
</html>
Blank.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Blank</title>
</head>
<body>
<h2>Username or Password cannot be blank</h2>
<form action="Jsp_Login.jsp" method="get">
<input type="Submit" value="Go Back!!">
</input>
</form>
</body>
</html>
Welcome.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Welcome ${U_name} </h2>
</body>
</html>
0 comments:
Post a Comment