On Tue, 2004-04-20 at 13:21, Brian Engel wrote:
> Does anybody know if there is a way to "turn off" URL Rewriting in
> Tomcat for session ID's?
> i.e. So that ;jsessionid=blah doesn't get appended to the URL.
>
I am not sure if there is a way to do this without
violating the Servlet spec, but I do it selectively
(based on agent name, for instance) by using a Filter
and a HttpServletResponseFilter like so:
(formatting mangled a bit for 80 cols...)
----------------------------------------------------------------------------
public class SessionIdFilter implements Filter
{
...
public void doFilter( ServletRequest req,
ServletResponse resp,
FilterChain chain )
throws IOException,
ServletException {
if ( <some condition> ) {
resp = new HttpServletResponseWrapper((HttpServletResponse)resp) {
public String encodeURL(String s) {
return s;
}
public String encodeRedirectURL(String s) {
return s;
}
public String encodeUrl(String s) {
return s;
}
public String encodeRedirectUrl(String s) {
return s;
}
};
}
chain.doFilter( req, resp );
}
}
The filter needs to be defined in web.xml as well, like this:
<web-app>
<filter>
<filter-name>Session Id Filter</filter-name>
<filter-class>some.name.SessionIdFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Session Id Filter</filter-name>
<servlet-name>yourServlet</servlet-name>
</filter-mapping>
[...other stuff...]
</web-app>
Hope this is helpful,
--
Robert Fries
Objective Synthesis
|