2011-02-11 31 views
3

我在Tomcat上运行基于Spring框架的Web应用程序。我的要求是,任何来到服务器的请求都应该到达一个servlet。所以我的conf/web.xml中作了如下配置HttpServletRequest的getRequestURL()不返回确切的URL

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

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

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

在这种情况下可以得到确切的URL吗? 请帮忙

+3

的可能重复[JSP/Servlet的HTTP 404错误处理] (http://stackoverflow.com/questions/3336501/jsp-servlet-http-404-error-handling) – BalusC 2011-02-11 13:50:48

回答

1

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

您可以用拉

request.getAttribute实际的URL(\ “javax.servlet.forward.request_uri \”)。的toString()

+0

是的,这返回uri。 request.getRequestURL()给出了http:// localhost字符串。这两个字符串的连接有所帮助。 谢谢。 – ihavprobs 2011-02-16 06:50:39