-1

我有一个类似的网址

www.abc.com/;jsessionid=53AA662D24A89922031913A6E85A005B

(对不起,我不能在这里指定我的实际站点名称,所以使用abc.com

当上面的 url 被点击时,我想;jsessionid=53AA662D24A89922031913A6E85A005B在后端(在我的 servlet 中)从上面的 url 中剥离并重定向到实际的 url(在这个例子中 http://www.abc.com/)。

我在我的 servlet 中尝试了多种方法来了解请求的 URL 是否具有“jsessionid”,但我找不到在 HTTP 请求对象上返回完整请求的 URL 的方法

我在 HTTP 请求对象上尝试了以下方法

  • getRequestURI()
  • getRequestURL()
  • getContextPath()
  • getPathInfo()

但他们没有返回带有jsessionid.

我试过了getParameter()getParameterNames()但没有帮助,因为上面的 url?以前没有jsessionid

4

2 回答 2

8

这是在 Servlet 中检索上述完整 url 的方法

 public void doGet(HttpServletRequest request, HttpServletResponse response)
                       throws IOException, ServletException {

               String url = request.getRequestURL().toString();
              System.out.println(url);
               }
于 2013-06-12T14:51:56.893 回答
2
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

    String jSessionId=request.getParameter("jsessionid");

    System.out.println("jSessionId:"+jSessionId);    
}
于 2014-02-26T05:44:18.237 回答