Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent adding jsessionid at the end of redirected url

I am trying to redirect to foreign domain url from my servlet. But the redirection adds ;jsessionid=ghdssdf... at the end of url. I do not know how I can prevent appending jsession id to my url. My app is running on Websphere

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

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

like image 785
gabby Avatar asked Apr 17 '15 06:04

gabby


People also ask

How do I stop Jsessionid in URL?

Set sessionManager. sessionIdUrlRewritingEnabled = false to disable appending JSESSIONID to the URL. NOTE: if a user has disabled cookies, they will NOT be able to login if this is disable.

Why does URL show Jsessionid?

The JSESSIONID is used to ensure that loadbalancers properly route communications to and from the correct client/server partners. By default, Oracle Forms requests a JSESSIONID be generated and maintained in the URL of each exchange between the client and server.

How do I redirect a URL in Java?

The sendRedirect() method of HttpServletResponse interface can be used to redirect response to another resource, it may be servlet, jsp or html file. It accepts relative as well as absolute URL. It works at client side because it uses the url bar of the browser to make another request.

What is redirect script?

A JavaScript redirect is used to instruct a browser to load another URL. An example of what a JavaScript redirect may look like when we're sending visitors to https://www.contentkingapp.com/ after rendering the page: <script>window.location.replace("https://www.contentkingapp.com/");</script>


1 Answers

It appears that you're confused by the badly chosen method name encodeRedirectURL(). It does not perform any "URL encoding" ("dealing with special characters") as the method name implies. It merely performs "URL rewriting" by appending the current session ID as path parameter. This is intented to be used when rendering internal links on the web page (usually via JSTL <c:url> in JSP pages, or JSF <h:link> in Facelets pages), so that the HTTP session is maintained in case the client has cookies disabled.

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

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

See also:

  • In the context of Java Servlet what is the difference between URL Rewriting and Forwarding?

Unrelated to the concrete problem: URL rewriting could be turned off by adding the below entry to webapp's web.xml, which instructs the container to use a "Cookie only" policy as to maintaining the HTTP session.

<session-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>
like image 127
BalusC Avatar answered Nov 15 '22 02:11

BalusC