【问题标题】:How to get the request url from HttpServletRequest [duplicate]如何从 HttpServletRequest 获取请求 url [重复]
【发布时间】:2011-02-21 02:07:50
【问题描述】:

假设我发出这样的获取请求:

GET http://cotnet.diggstatic.com:6000/js/loader/443/JS_Libraries,jquery|Class|analytics|lightbox|label|jquery-dom|jquery-cookie?q=hello#frag HTTP/1.0
Host: cotnet.diggstatic.com:6000

我的 servlet 接受这样的请求: HttpServletRequest 请求;

当我调试我的服务器并执行时,我得到以下信息:

req.getRequestURL().toString() = "http://cotnet.diggstatic.com:6000/js/loader/443/JS_Libraries,jquery%7cClass%7canalytics%7clightbox%7clabel%7cjquery-dom%7cjquery-cookie"
req.getRequestURI() = "/js/loader/443/JS_Libraries,jquery%7cClass%7canalytics%7clightbox%7clabel%7cjquery-dom%7cjquery-cookie"
req.getQueryString() = "q=hello"

如何获取片段信息? 此外,当我调试请求时,我看到一个 java.net.URI 类型的 uri_ 字段,其中包含片段信息。这正是我想要的。我怎样才能得到它?

【问题讨论】:

    标签: http url servlets uri


    【解决方案1】:

    “片段标识符的功能与 URI 的其余部分不同:即,它的处理仅在客户端进行,没有服务器的参与。” Wikipedia about the Frament Identifiert

    如需进一步参考,请参阅RFC 2394 Section 4.1

    【讨论】:

      猜你喜欢
      • 2011-12-27
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多