File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to end session after LogOut in struts application

 
Rohit Mehta
Ranch Hand
Posts: 79
Chrome Eclipse IDE Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

  •  
    peter wooster
    Ranch Hand
    Posts: 1033
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 3
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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>
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic