I’ve noticed that google indexed various pages of mine with appended “;jsessionid=somehash”
Thats not only ugly, but also a security risk.
But how to disable Session Tracking by URL? How to set it to Cookie only ?
Take this!
Update: Jan Luehe showed me a way, how to do this in web.xml only – without a listener
1 2 3 4 5 6 7 | <web-app ...> <session-config> <tracking-mode>COOKIE</tracking-mode> <tracking-mode>URL</tracking-mode> <tracking-mode>SSL</tracking-mode> </session-config> </web-app> |
if you prefer to do it programmatically (e.g. when doing a custom web-app configuration wizzard or something like this), do it this way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | package com.dominikdorn.dc.listeners; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.SessionTrackingMode; import javax.servlet.annotation.WebListener; import java.util.HashSet; import java.util.Set; /** * This Listener sets the tracking modes used by the servletContext */ @WebListener(value = "This listener sets the session tracking modes") public class SetSessionTrackingModeListener implements ServletContextListener { // Public constructor is required by servlet spec public SetSessionTrackingModeListener() { } public void contextInitialized(ServletContextEvent sce) { Set<SessionTrackingMode> modes = new HashSet<SessionTrackingMode>(); // modes.add(SessionTrackingMode.URL); // thats the default behaviour! modes.add(SessionTrackingMode.COOKIE); // modes.add(SessionTrackingMode.SSL); // this works only with client certs. sce.getServletContext().setSessionTrackingModes(modes); } public void contextDestroyed(ServletContextEvent sce) { } } |
Questions? Comments? Post them here!
2 Responses to Disabling ;jsessionid url-appending Servlet 3.0
[solved] url rewrite removing the ;jsessionid= from the url « OcpSoft Support Forums
January 6th, 2012 at 22:05
[…] the Resinator you might as well simply disable appending of the jsessionid http://dominikdorn.com/2010/03/disabling-jsessionid-url-appending-servlet-3-0/ Posted 1 year ago […]
Google Bot - removal of jsessionid - possible? « OcpSoft Support Forums
January 6th, 2012 at 22:22
[…] the Resinator http://dominikdorn.com/2010/03/disabling-jsessionid-url-appending-servlet-3-0/ Posted 6 months ago […]