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
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.
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.
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.
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>
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");
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With