0

In my Spring MVC application I have to display a Error page once the session is invalidated. For session invalidation , I am using the following code :

<session-config>
        <session-timeout>1</session-timeout> 
    </session-config>

In this case after once minute the session expires.On any event in the page here ,the user should be populated with error page where I can redirect to login page again.

P.S: I not using Spring security and will not be.

Goutham
  • 80
  • 12

1 Answers1

0

You should be using the HttpSessionListener for session management. Register the listener in web.xml via

<listener>
   <listener-class>com.example.customSessionListener</listener-class>
</listener>

Create a class which extends implements HttpSessionListener. Override the sessionDestroyed method and do whatever you need here for session tracking .

For redirection, you may want to put a check somewhere in the controller to see if the user is still in session and if not route it somewhere else.

Aravind A
  • 9,507
  • 4
  • 36
  • 45
  • Nice , However a piece of code for the redirection would be of great help. Thanks in advance. – Goutham Dec 12 '11 at 05:51
  • Check http://www.xyzws.com/Servletfaq/when-do-i-use-httpsessionlistener/7 for a sample on httpsessionlistener . You could do a httpServletRequest.getSession().getAttribute("userID") in your controller- If the session has timed out, this is likely to be null and you can redirect the page through response.sendRededirect("url") - I am assuming that you would have set the userID in a session attribute for session tracking. – Aravind A Dec 12 '11 at 06:50