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.
Everything is much simpler with Servlet API 3.0.
Now you can configure it in your web.xml:
<session-config>
<cookie-config>
<name>MY_JSESSIONID_YAHOOOOOO</name>
</cookie-config>
</session-config>
That's it!
The following works for me on Tomcat7 in the context.xml file:
<Context path="/yourApp" sessionCookieName="custom_session_id">
By Using two following system properties this can be achieved with ease.
- org.apache.catalina.SESSION_COOKIE_NAME
- org.apache.catalina.SESSION_PARAMETER_NAME
Any value can be passed to above properties to change the default values.
Here complete details with some sample script is found.