Sat Jan 24, 2009 1:12 am
<HTML>
<HEAD>
<TITLE>Login using JSP</TITLE>
</HEAD>
<BODY>
<H1>LOGIN FORM</H1>
<%
String myname = (String)session.getAttribute("username");
if(myname!=null)
{
out.println("Welcome "+myname+" , <a href=\"logout.jsp\" >Logout</a>");
}
else
{
%>
<form action="checkLogin.jsp">
<table>
<tr>
<td> Username : </td><td> <input name="username" size=15 type="text" /> </td>
</tr>
<tr>
<td> Password : </td><td> <input name="password" size=15 type="text" /> </td>
</tr>
</table>
<input type="submit" value="Login" />
</form>
<%
}
%>
</BODY>
</HTML>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
out.println("Checking login<br>");
if (username == null || password == null) {
out.print("Invalid parameters ");
}
// Here you put the check on the username and password
if (username.toLowerCase().trim().equals("admin") && password.toLowerCase().trim().equals("admin")) {
out.println("Welcome " + username + " <a href=\"index.jsp\">Back to main</a>");
session.setAttribute("username", username);
}
else
{
out.println("Invalid username and password");
}
%>
<%
String username=(String)session.getAttribute("username");
if(username!=null)
{
out.println(username+" loged out, <a href=\"index.jsp\">Back</a>");
session.removeAttribute("username");
}
else
{
out.println("You are already not login <a href=\"index.jsp\">Back</a>");
}
%>
<META http-equiv="refresh" content="3;URL=index.jsp">
<%
response.sendRedirect("index.jsp");%>
Wed Mar 25, 2009 5:33 am
Tue Jan 25, 2011 2:34 pm
Thu Jun 30, 2011 1:29 pm
Tue Jul 26, 2011 7:21 am
Fri Oct 07, 2011 7:01 am
Sat Nov 05, 2011 9:50 am
krrish wrote:Hi,
In your program,there is a bug.That is if you click the logout link,it'll take you to the index page but after that if you click the back button,it'll again take you the welcome page .Please check it....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
<title>SOLVING LOGOUT PROBLEM EFFICIENTLY USING JSP</title>
</head>
<body bgcolor="#99FF66">
<center><h1>login</h1></center>
<center>
<form nme="login" method="post" action="login.jsp">
<table>
<tr>
<td>name:</td>
<td><input type="text" name="name" align="right" /></td>
</tr>
<tr>
<td>password:</td>
<td><input type="password" name="password" align="right" /></td>
</tr>
<tr>
<td>
</td>
<td><center><input type="submit" name="submit" /></center></td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>
Read more: http://wiki.answers.com/Q/How_do_you_clear_the_browser_cache_in_jsp#ixzz1c6g2F9jR
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<% String fname=null,fpassword=null;
try
{
session.setAttribute("name",null);
session.setAttribute("password",null);
fname=request.getParameter("name");
fpassword=request.getParameter("password");
if(fname.equals("kiran")&&fpassword.equals("kiran"))
{
session.setAttribute("name",fname);
session.setAttribute("password",fpassword);
%>
<jsp:forward page="welcome.jsp"/>
<%
}
else
{
%>
<jsp:forward page="sample.html"/>
<%
}
}
catch(Exception e)
{
System.out.println("errror"+e);
}
%>
</body>
</html>
**welcome.jsp**
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<%
if((session.getAttribute("name"))!=null&&(session.getAttribute("password")!=null))
{
%>
<body bgcolor="#99FF66"><center>
<p>welcome<%=session.getAttribute("name")%> </p><h1 align="right"><a href="logout.jsp">logout</a></h1>
<p> </p>
<p> </p>
<p> </p><table width="100"><tr><td align="center"><a href="x.jsp">x</a></td><td align="center"><a href="y.jsp">y</a></td></tr>
<tr><td align="center"><a href="z.jsp">z</a></td><td align="center"><a href="p.jsp">p</a></table>
</center>
</body>
<%
}
else
{
%>
<jsp:forward page="sample.html"/>
<%
}
%>
</html>
then the links x.jsp,y.jsp,z.jsp,p.jsp all look same.
**x.jsp**
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<%
if((session.getAttribute("name"))!=null&&(session.getAttribute("password")!=null))
{
%>
<body bgcolor="#99FF66"><h1 align="center">x</h1>
<h1 align="right"><a href="logout.jsp">logout</a></h1>
<center>
<table width="100"><tr><td align="center"><a href="#">x</a></td><td align="center"><a href="y.jsp">y</a></td></tr>
<tr><td align="center"><a href="z.jsp">z</a></td><td align="center"><a href="p.jsp">p</a></table>
</center>
</body>
<%
}
else
{
%>
<jsp:forward page="sample.html"/>
<%
}
%>
</html>
**y.jsp**
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<%
if((session.getAttribute("name"))!=null&&(session.getAttribute("password")!=null))
{
%>
<body bgcolor="#99FF66"><h1 align="center">y</h1>
<h1 align="right"><a href="logout.jsp">logout</a></h1>
<center>
<table width="100"><tr><td align="center"><a href="x.jsp">x</a></td><td align="center"><a href="#">y</a></td></tr>
<tr><td align="center"><a href="z.jsp">z</a></td><td align="center"><a href="p.jsp">p</a></table>
</center>
</body>
<%
}
else
{
%>
<jsp:forward page="sample.html"/>
<%
}
%>
</html>
**z.jsp**
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<%
if((session.getAttribute("name"))!=null&&(session.getAttribute("password")!=null))
{
%>
<body bgcolor="#99FF66"><h1 align="center">z</h1>
<h1 align="right"><a href="logout.jsp">logout</a></h1>
<center>
<table width="100"><tr><td align="center"><a href="x.jsp">x</a></td><td align="center"><a href="y.jsp">y</a></td></tr>
<tr><td align="center"><a href="#">z</a></td><td align="center"><a href="p.jsp">p</a></table>
</center>
</body>
<%
}
else
{
%>
<jsp:forward page="sample.html"/>
<%
}
%>
</html>
**p.jsp**
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<%
if((session.getAttribute("name"))!=null&&(session.getAttribute("password")!=null))
{
%>
<body bgcolor="#99FF66"><h1 align="center">p</h1>
<h1 align="right"><a href="logout.jsp">logout</a></h1>
<center>
<table width="100"><tr><td align="center"><a href="x.jsp">x</a></td><td align="center"><a href="y.jsp">y</a></td></tr>
<tr><td align="center"><a href="z.jsp">z</a></td><td align="center"><a href="#">p</a></table>
</center>
</body>
<%
}
else
{
%>
<jsp:forward page="sample.html"/>
<%
}
%>
</html>
and finally on logout the code is as follows :
**logout.jsp**
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<%
session.removeAttribute("name");
session.removeAttribute("password");
session.invalidate();
%>
<jsp:forward page="sample.html"/>
</body>
</html>
Mon Nov 07, 2011 7:21 am
Guest wrote:Thats it hope it solves the logout problem
for any queries contact me at [email protected] or [email protected]
Mon Jan 02, 2012 2:16 pm
mahes wrote:hi i want to check it from the database please any one help me
Mon Jan 23, 2012 7:23 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.