Java – Changing cookie JSESSIONID name


I have a requirement of having to run multiple tomcat server in single physical box. While accessing these from a browser, when user switches between the applications, it results in logging out the user previously access application. This is because of JSESSIONID cookie conflict.

One possible solution is to run each applications in different context. Unfortunately, my applications will not work in context path setting as none of the resources are accessed with request.getContextPath() prepended in front.

This leaves me to change the name of cookie JSESSIONID to resolve the conflict. Is there a way to do this? If yes, how?

Hope I'm clear in stating my question.

Note: All my application are running in different port in the same machine.

Best Answer

Everything is much simpler with Servlet API 3.0.

Now you can configure it in your web.xml:


That's it!

Related Topic