How to prevent jsessionid from being added at the end of the redirected url

I am trying to redirect a foreign domain url from my servlet. But the redirect adds ; jsessionid = ghdssdf ... at the end of the url. I don't know how I can prevent from adding jsession id to my url. My application is running in Websphere

resp.sendRedirect(resp.encodeRedirectURL("https://www.facebook.com/mymage"));

      

the end of the directed url can be seen in the browser as https://www.facebook.com/mymage;jsessionid=dfsdfsd

+3


source to share


1 answer


It looks like you are confused by the poorly chosen method name encodeRedirectURL()

. It does not do any "URL encoding" ("with special characters") as the method name suggests. It simply does "URL rewriting" by adding the current session id as a path parameter. This is intended to be used when rendering internal links on a web page (usually via JSTL <c:url>

on JSP pages or JSF <h:link>

on Facelets pages) so that an HTTP session is maintained in case the client has cookies disabled.

You don't need it here at all. Just pass the URL directly:

response.sendRedirect("https://www.facebook.com/mymage");

      

See also:




Unrelated to the specific issue: URL rewriting can be disabled by adding the following webapp entry web.xml

stating that the container uses a cookie-only policy to support HTTP sessions.

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

      

+5


source







All Articles