• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to end session after LogOut in struts application  RSS feed

 
Ranch Hand
Posts: 79
Chrome Eclipse IDE Spring
  • 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
 
Ranch Hand
Posts: 4864
  • 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.

  •  
    Ranch Hand
    Posts: 1033
    • 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.
     
    Greenhorn
    Posts: 3
    • 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
    Boost this thread!