• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with session

 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the following code i am logging out and making the session invalid.But if i click on the back button it's going back to the previous screen.i am unable to figure it out.Can anyone help me out.
Thanks in advance.


import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Logout extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
PrintWriter out = res.getWriter();
System.out.println("1");
try
{
HttpSession session = req.getSession(false);
if (session != null) {
session.invalidate();
}
}catch(Exception e)
{
System.out.println(e);
}
System.out.println("2");

res.setContentType("text/html");
try
{
System.out.println("4");
ServletConfig config = getServletConfig();
System.out.println("5");
ServletContext context = config.getServletContext();
System.out.println("6");
RequestDispatcher rd = context.getRequestDispatcher("/apps/Login.html");
System.out.println("7");
rd.forward(req,res);
System.out.println("8");

}catch(Exception e)
{
out.println(e);
}
}
}
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the most likely that the browser is showing the page up from its proxy on back button press.

Otherwise you can check the session before processing any request. Say you have an attribute in session that is a boolean. On successful login you can set that to true and upon logout you just invalidate the session. So, now on you can check that attribute, present in the session, before processing any request.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use in your code before starting page writing

http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!