【问题标题】:How to get the full url from HttpServletRequest? [duplicate]如何从 HttpServletRequest 获取完整的 url? [复制]
【发布时间】:2014-07-04 18:24:29
【问题描述】:

好的,我有这些代码:

HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestQueryString = httpRequest.getQueryString();
System.out.println(requestQueryString);

打开网址“http://127.0.0.1:8888/MyProject.html?gwt.codesvr=127.0.0.1:9997?_escaped_fragment_=home”时,

打印出来了:

 gwt.codesvr=127.0.0.1:9997?_escaped_fragment_=home

该网址缺少http://127.0.0.1:8888/MyProject.html? 部分。

如何解决?

【问题讨论】:

  • 阅读HttpServletRequest的javadoc。都在里面。
  • 它没有 getFullURL,我们必须构建单独的部分,但我正在寻找可以完成这项工作的 1 行代码
  • 检查这篇文章这个问题似乎是重复的,..stackoverflow.com/questions/2222238/…

标签: java servlets


【解决方案1】:

应该是

httpRequest.getRequestURL() + "?" + httpRequest.getQueryString()

打印

http://127.0.0.1:8888/MyProject.html?gwt.codesvr=127.0.0.1:9997?_escaped_fragment_=home

【讨论】:

  • 如果网址是“xcd.com#!br”,那么您的代码可以正常工作吗?
  • @tum #... 不应该在请求中发送。仅供客户端使用。
  • 片段未在 HTTP 标头中发送:blog.httpwatch.com/2011/03/01/…
猜你喜欢
  • 1970-01-01
  • 2011-02-21
  • 2014-07-21
  • 1970-01-01
  • 1970-01-01
  • 2013-01-16
  • 1970-01-01
  • 2020-02-11
  • 2012-12-06
相关资源
最近更新 更多