my dog learned polymorphism*
The moose likes Struts and the fly likes How to end session after LogOut in struts application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to end session after LogOut in struts application" Watch "How to end session after LogOut in struts application" New topic
Author

How to end session after LogOut in struts application

Rohit Mehta
Ranch Hand

Joined: Mar 11, 2005
Posts: 79

Hi all

A struts based site,

Problem is that after logout, if i click to "back" button from browser, i am on previous page & can do any operation successfully, as login.

Can anybody tell me how to handle it?

thanks


- Rohit
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Here is what you need to do:
  • when the user logs out, make sure to call invalidate() on the HTTPSession object.
  • In each action class, call getSession(false) on the HttpServletRequest object. If it returns null, the user has no session, and you can force them to log on before continuing.
  • As an added measure, Even if the user does have a session, use the getAttribute method to check for the existence of some object, such as a user object which is placed in the session when the user logs on. If it isn't there, make the user log on again.


  • Merrill
    Consultant, Sima Solutions
    peter wooster
    Ranch Hand

    Joined: Jun 13, 2004
    Posts: 1033
    What I do is to create a SessionState object that I save in the HttpSession as an attribute. I use this object to store all session related data and set it to null at logout. This class has a static method that gets the instance given the request object. It throws a SessionLostException if the attribute is null and I have a global exception handler that then redisplays the logon page when this occurs.
    Nishant Sahay
    Greenhorn

    Joined: Jul 29, 2003
    Posts: 3
    Originally posted by rohit mehta:
    Hi all

    A struts based site,

    Problem is that after logout, if i click to "back" button from browser, i am on previous page & can do any operation successfully, as login.

    Can anybody tell me how to handle it?

    thanks


    You can use the struts RequestProcessor class. As per struts architecture any request before reaching the action class passes through the RequestProcessor.
    We can use RequestProcessor class by extending it with our custom class. IN the custom class we can do the login check and in case of failure dispatch the request to session expire jsp.

    if( session != null && session.getAttribute("userName") != null)
    return true;
    else{
    try{
    //If no redirect user to login Page request.getRequestDispatcher ("/Login.jsp").forward(request,response); }catch(Exception ex){ } }

    In the struts config we need to make the following entry

    <controller> <set-property property="processorClass" value="com.sample.util.CustomRequestProcessor"/> </controller>
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to end session after LogOut in struts application