简体   繁体   中英

How to remove jsessionid from URL in my local Tomcat7 in Eclipse

I have a java web app that I deploy in production with Tomcat7. I use the Tomcat Web Application Manager page in production, where I deploy my WAR at the context path "/". In production I'm not seeing jsessionid in URL.

In my development environment though, the same application (hence the same web.xml ), started with Tomcat7 inside eclipse is showing jsessionid in URL.

The only session configuration I have in my web.xml is:

<session-config>
    <session-timeout>15</session-timeout>
</session-config>

The only difference I can see in both Tomcat7 is the server.xml :

Production:

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

Local:

  <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
    <Context docBase="MyApp" path="/" reloadable="true" source="org.eclipse.jst.jee.server:MyApp"  />
  </Host>

Another difference is that I use NGinx in production to do a proxy pass from port 80 to 8080 from Tomcat.

What may I be missing?

Thanks

You may using a browser or other client that doesn't support (or disabled) cookies in your development environment.

Another Tip: you may use this code in tomcat 7 (in your web.xml file):

<session-config>
     <tracking-mode>COOKIE</tracking-mode>
</session-config>

The problem is that for cookies to work properly, the domain name must have at least two dots ( https://curl.haxx.se/rfc/cookie_spec.html ).

So to make it work locally, I had to do the following:

Change the /etc/hosts file to include any domain name with at least one period, pointing to 127.0.0.1:

127.0.0.1       localhost
127.0.0.1       localhost.test
255.255.255.255 broadcasthost
::1             localhost

Change the context.xml to include the new domain:

<Context sessionCookieDomain=".localhost.test" sessionCookiePath="/"> 
...
</Context>

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