aspose file tools
The moose likes Servlets and the fly likes Problem with session Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Problem with session" Watch "Problem with session" New topic
Author

Problem with session

visu Nekk
Ranch Hand

Joined: Sep 06, 2005
Posts: 122
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Oct 09, 2002
Posts: 294
Use in your code before starting page writing

http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Problem with session
 
Similar Threads
Please answer these few doubts
NoRouteToHostException pop3 client
NoRouteToHostException need urgent help
servlet cant see getServletContext() from inheritance
problem with urldecoder in doGet mehtod