Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing cookie JSESSIONID name

People also ask

Who sets Jsessionid cookie?

JSESSIONID cookie is created by web container and send along with response to client.

Is Jsessionid and session ID same?

The JSESSIONID is generated from the servlet-container like jetty or tomcat or the builtin if you run a grails app standalone. The session-id is generated from the used http-server like apache, etc.

What is Jsessionid in cookie?

JSESSIONID is a cookie generated by Servlet containers and used for session management in J2EE web applications for HTTP protocol. If a Web server is using a cookie for session management, it creates and sends JSESSIONID cookie to the client and then the client sends it back to the server in subsequent HTTP requests.

Why is Jsessionid in URL?

The JSESSIONID is used to ensure that loadbalancers properly route communications to and from the correct client/server partners. By default, Oracle Forms requests a JSESSIONID be generated and maintained in the URL of each exchange between the client and server.


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.


Tomcat 7 moves this from org.apache.catalina.SESSION_COOKIE_NAME to an attribute on the main <Context> config. http://tomcat.apache.org/migration-7.html#Session_manager_configuration


I don't think it's possible at this point - see https://issues.apache.org/bugzilla/show_bug.cgi?id=42419

The last entry states "This has been fixed in 5.5.x and will be included in 5.5.28 onwards" - which is the next point release - 5.5.27 is the current release.


Not 100% sure if this will work, but you can use the jvmRoute attribute, which is generally used in a load-balanced/clustered environment for the load balancers to be able to tell the nodes apart. Example:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="node1">

This will end up generating a JSESSIONID value that looks like "ABCDEF123456.node1".

Documentation link.