如何防止在重定向的URL末尾添加jsessionid [英] How to prevent adding jsessionid at the end of redirected url

查看:378
本文介绍了如何防止在重定向的URL末尾添加jsessionid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的servlet重定向到外部域url.但是重定向会在url的末尾添加; jsessionid = ghdssdf ... .我不知道如何避免将jsession id附加到我的网址中.我的应用程序正在Websphere上运行

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"));

在浏览器中可以将定向网址结尾显示为 https://www.facebook.com/mymage; jsessionid = dfsdfsd

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

推荐答案

似乎您对错误选择的方法名称encodeRedirectURL()感到困惑.它不执行方法名称所暗示的任何"URL编码"(使用特殊字符处理").它仅通过将当前会话ID附加为路径参数来执行"URL重写".旨在在网页上呈现内部链接时使用此链接(通常通过JSP页面中的JSTL <c:url>或Facelets页面中的JSF <h:link>),以便在客户端禁用cookie的情况下维护HTTP会话.

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");

另请参见:

  • 在Java Servlet的上下文中,URL重写和转发之间有什么区别?
  • See also:

    • In the context of Java Servlet what is the difference between URL Rewriting and Forwarding?
    • 无关:与具体问题无关:可以通过在webapp的web.xml中添加以下条目来关闭URL重写,该条目指示容器使用仅Cookie"策略来维护HTTP会议.

      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>
      

      这篇关于如何防止在重定向的URL末尾添加jsessionid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆