Tomcat 7 : Redirect URL in case of session timeout

2019-04-14 08:00发布

问题:

I have following configuration in web.xml in tomcat 7. I am wondering if I can add any configurable parameter here, so that if user tries to do any operation post 30 minutes, I redirect the user to our home page.

<session-config>
      <session-timeout>30</session-timeout>
      <cookie-config>
              <domain>mydomain.mycompany.com</domain>
              <http-only>true</http-only>
              <secure>false</secure>
      </cookie-config>
      <tracking-mode>COOKIE</tracking-mode>
</session-config>

回答1:

This is probably not possible by configuration only. You will have to add a filter aswell. One way of doing that is described here: https://stackoverflow.com/a/1027592/3417638

If you would like to configure the redirect in web.xml, this can be done by using a context-parameter, see: https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Context_Parameters