You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mike Heckler <mi...@arkivmusic.com> on 2003/06/20 17:26:31 UTC

Configuring session Id in URL

Is there a way to tell tomcat to NOT place the session ID in a url
(even when the client doesn't support cookies) based on IP or user-agent?

The problem I'm having is with search engines (especially google) not 
indexing
my entire site because the URLs have the jsessionid in them.  I'd like 
to support
browsers with cookies turned off, but at the same time not send the 
jsessionids
to certain clients.

I've looked around and can't seem to even the question anywhere, let 
alone the answer.

Thanks,
Mike Heckler


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Configuring session Id in URL

Posted by Tim Funk <fu...@joedog.org>.
Ouch! But the answer is easy. Filters with HttpServletResponseWrapper. Here 
is a quick example:

public class NoRewriteFilter implements Filter {

     public void init(FilterConfig filterConfig)
               throws ServletException {
         ;
     }

     public void doFilter(ServletRequest request,
                          ServletResponse response,
                          FilterChain chain)
                   throws IOException,
                          ServletException {

         if (canIgnoreRewrite(request)) {
             response = new 
HttpServletResponseWrapper((HttpServletResponse)response) {
                             public String encodeRedirectUrl(String url) {
                                 return url;
                             }
                             public String encodeRedirectURL(String url) {
                                 return url;
                             }
                             public String encodeUrl(String url) {
                                 return url;
                             }
                             public String encodeURL(String url) {
                                 return url;
                             }
                         }
         chain.doFilter(request,response);
     }

     public void destroy() {
         ; // no-op
     }


     protected boolean canIgnoreRewrite(ServletRequest request) {
         HttpServletRequest r = (HttpServletRequest)request;
         String agent = r.getHeader("user-agent");

         if (agent!=null)
             return false;
         agent = agent.toLowerCase();
         return agent.indexOf("googlebot")>-1;
     }

}




-Tim

Mike Heckler wrote:
> Is there a way to tell tomcat to NOT place the session ID in a url
> (even when the client doesn't support cookies) based on IP or user-agent?
> 
> The problem I'm having is with search engines (especially google) not 
> indexing
> my entire site because the URLs have the jsessionid in them.  I'd like 
> to support
> browsers with cookies turned off, but at the same time not send the 
> jsessionids
> to certain clients.
> 
> I've looked around and can't seem to even the question anywhere, let 
> alone the answer.
> 
> Thanks,
> Mike Heckler
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org