Pr.Pg Next Pg

Simple Login Program using Session tutorials

 

JSP action page for login.html

Sam Sir

<%-- Program name Action.jsp--%>

<%-- JSP action page for login.html --%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<%

String str = request.getParameter("UserName");

String paaawd=request.getParameter("Password");

session.setAttribute("UserName", request.getParameter("UserName"));

if(str.equals("Sam") && paaawd.equals("SamComputers"))

{

%>

Welcome <%= session.getAttribute( "UserName" )%><a href="logout.jsp"><b>Logout</b></a>

<%} else

{%>

User Name or Password is incorrect please <a href="Login.html"><b>Login </b></a>

<%}%>

</body>

</html>

 

 


 

JSP program to destroy session and attributes which was created in Action.jsp program

Sam Sir

<%-- Program name logout.jsp --%>

<%-- JSP program to destroy session and attributes which was created in

Action.jsp program --%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Logout Page</title>

</head>

<body>

<%session.invalidate();%>

You have logged out. Plese

<a href="Login.html"><b>Login</b></a>

</body>

</html>

 

 

 

 

HTML login program

Sam Sir

<!—Program name Login.html -->

<html>

<head>

<title>User Login</title>

</head>

<body>

<hr>

 

<form method="post" action="Action.jsp">

<table>

<tr>

<td><b>UserName:</b></td>

<td><input type="text" name="UserName" size="20"></td>

</tr>

<tr>

<td><b>Password:</b></td>

<td>

<input type="Password" name="Password" size="20">

</td>

</tr>

<tr>

<td></td>

<td>

<input type="submit" value="Submit" name="submit">

&nbsp;&nbsp; <input type="reset" value="Reset" name="reset">

</td>

</tr>

</table>

</form>

</body>

</html>

Output

Login

 

Login

 

Session login

 

Logout

Pr.Pg border                                              Next Pg