5

I have created an login page in servlet using Google Datastore, it is working fine. but sometimes its showing the JSESSIONID in the URL.

How can I prevent the JSESSIONID sending through the URL? why its passing through the URL instead of request message?

Prakash
  • 569
  • 2
  • 9
  • 17

2 Answers2

5

Add the following entry in your web.xml.

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

This will instruct the container that the client supports cookies and hence there is no need to put the JSessionId in the URL.

VHS
  • 9,185
  • 3
  • 17
  • 41
3

Are you using response.encodeURL()? If so, try to remove it or disable "URL Rewriting" and check the URL.

See also:

  • disableURLRewriting

Apache Tomcat Configuration Reference

Additional information:

response.encodeURL(URL) adds ;jsessionid=xxxx... to URL. To disable this(="URL Rewriting"),

Tomcat 7.0 or later:

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

Tomcat 6.0:

<Context disableURLRewriting="true" ...
Kohei TAMURA
  • 4,778
  • 6
  • 23
  • 44
  • No I am not using `response.encodeURL()`, – Prakash Jun 23 '17 at 05:56
  • You should *always* use `response.encodeURL` (or `response.encodeRedirectURL` if appropriate). If you want to disable sessions, use the configuration instead of breaking your application by not following the rules. – Christopher Schultz Apr 26 '18 at 13:13