开发者

How to get original page url/uri after request dispatcher forward

I have a Error404Servlet which is configured as error-page for 404 in web.xml:

   <servlet>
      <servlet-name>Error404</servlet-name>
      <servlet-class>com.foo.bar.Error404Servlet</servlet-class>
   </servlet>

   <error-page>
      <error-code>404</error-code>
      <location>/error404</location>
   <开发者_如何学Go/error-page>

In this servlet i have to log the original url that caused 404, but request.getRequestURI() always returns "/error404"

How can i get the original url? The unly ugly method i know is to create filter that puts the original url to request attribute.


From the request you can retrieve attributes set by the container in the event of an error:

request.getAttribute("javax.servlet.error.request_uri");

other attributes that can provide usefull information;

javax.servlet.error.status_code
javax.servlet.error.exception_type
javax.servlet.error.message
javax.servlet.error.exception

See also this servlet 2.3 features article.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜