You can't entirely disable it. All you need to do is to just not to get a handle of it by either request.getSession()
or request.getSession(true)
anywhere in your webapplication's code.
If your main concern is actually disabling the cookie which is been used behind the scenes of HttpSession
, then you can do so in the webapp's Context
element. In for example Tomcat you can set cookies
attribute to false
.
<Context cookies="false">
Also see this Tomcat specific documentation. This way the session won't be retained in the subsequent requests which aren't URL-rewritten --only whenever you grab it from the request for some reason. After all, if you don't need it, just don't grab it, then it won't be created/retained at all.
If you want to hardcode in your webapplication so that getSession()
never returns a HttpSession
(or an "empty" HttpSession
), then you'll need to create a filter listening on an url-pattern
of /*
which replaces the HttpServletRequest
with a HttpServletRequestWrapper
implementation which returns null
or throws UnsupportedOperationException
on all getSession()
methods.
P.S. Is this a bad idea? I prefer to completely disable things until I actually need them.
If you don't need them, just don't use them. That's all. Really :)