简体   繁体   中英

How to set tomcat session timeout per path?

I know how to change the global session-timeout in a tomcat8 :

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

Question: how can I change the timeout per application path ?

Like I want to deploy multiple applications to:

/myapp/v1
/myapp/v2
/myapp/v3
/someapp

Now I want all /myapp/* path to have a different timeout. But also only on the testserver. On the production server the timeout should be kept to default tomcat 30mins.

That's why I don't want to add a web.xml to the app itself, as this would also affect the production deployment when a new war is deployed.

Is that possible at all?

If that matters: I'm using spring-boot .

Your best bet is to probably handle this within a sessionhandler class, something along the lines of this:

public class AppHttpSessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent event) {
        event.getSession().setMaxInactiveInterval(15 * 60); 
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        // session destroyed
    }
}

Ref: http://www.groupkt.com/post/7ee95bbd/session-timeout-handling-in-java.htm

I could be wrong, but I'm not sure you can do this!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM