【问题标题】:getRequestURL() of HttpServletRequest not returning exact URLHttpServletRequest 的 getRequestURL() 未返回确切的 URL
【发布时间】:2011-02-16 02:47:07
【问题描述】:

我正在 Tomcat 上运行基于 Spring 框架的 Web 应用程序。我的要求是任何到达服务器的请求都应该到达单个 servlet。所以我在 conf/web.xml 中做了如下配置

<error-page>
    <error-code>404</error-code>
    <location>/displayMsg.do</location>
</error-page>

所以当用户访问 http://myhost/xyz 时,request.getRequestURL() 返回 http://myhost/displayMsg.do

我认为 requestURL() 返回此 url 的唯一原因是因为我所做的错误页面配置。可能是因为tomcat覆盖了这个字符串的url。

在这种情况下是否可以获得确切的 URL? 请帮忙

【问题讨论】:

标签: java tomcat


【解决方案1】:

几周前我遇到了同样的问题。

您可以使用拉取实际网址

request.getAttribute(\"javax.servlet.forward.request_uri\").toString()

【讨论】:

  • 是的,这将返回 uri。 request.getRequestURL() 给出localhost 字符串。这两个字符串的连接有帮助。谢谢。
猜你喜欢
  • 2012-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-14
  • 2012-02-14
  • 2012-04-12
  • 2018-05-26
  • 1970-01-01
相关资源
最近更新 更多