0

hi all, i tried following code for session management bt i dnt knw where it went wrong? can anyone please help me solve the problem. i want to restrict user going on the prevoius page after logging out when he clicks on the browser's BACK button.

******************************************************************
1) i created login.jsp as follows:

<p><a href="1.jsp">1</a></p>
   <%@ page contentType="text/html;language="java" import="java.sql.*">
   <%
	String username="vishal";
	request.getSession();
	out.println("<br>new session created");
	session.setAttribute("username",username);
	out.println("<br>"+session.getAttribute("username"));
   %>

*********************************************************************
2) then i created 1.jsp as follows:

<%@ page contentType="text/html;language="java" import="java.sql.*" %>
<html>
<body>
<p><a href="logout.jsp">logout</a></p>
<%
	if(session.getAttribute("username")==null)
		response.sendRedirect("Error.htm");	
%>
</body>
</html>

**********************************************************************
3) logout.jsp would be :

<%
	if(session.getAttribute("username")==null)
		response.sendRedirect("Error.htm");	
	else
	{
	  session.setAttribute("username",null);
	  session.invalidate();
	  response.sendRedirect("login.jsp");
	}
%>

*********************************************************************

but above code is not working. can anybody solve this problem? pls? or at least give some modification to it???

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

2
Contributors
2
Replies
6
Views
6 Years
Discussion Span
Last Post by vishalbhavsar
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.