Search This Blog

Session timeout interceptor in struts 2

Interceptor continue.....
If you want to use an interceptor which will check whether the session has been expired or not, if it is expired then it will forward to global view( like any jsp that you want to display after session timeout).

You need to do the following coding...1) Make an interceptor file SessionCheckInterceptor .java

3) Don't forget to see the session configuration in web.xml file under WEB-INF/classes directory

<session-config>

<session-timeout>30</session-timeout>

</session-config>

where 30 minutes represents maximum session time. So if a user is inactive till 30 minutes, session will be timeout and then if you are going to execute some action, interceptor will check the and forward you to the jsp whatever you have suggested in struts.xml under <global-results>

I had also written the same thing once for my <a href="http://www.javaexperience.com/force-page-to-login-after-struts2-session-timeout/'>struts2 application</a> and in addition what you have shown here, I had added javascript alert when the session is going to timeout.