如何在请求调度程序转发后获取原始页面url / uri [英] How to get original page url/uri after request dispatcher forward

查看:567
本文介绍了如何在请求调度程序转发后获取原始页面url / uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Error404Servlet,在web.xml中配置为404的错误页面:

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>
   </error-page>

在这个servlet中我必须记录导致404的原始url,但是request.getRequestURI()总是返回/ error404

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

我如何获得原始网址?我知道的非常难看的方法是创建过滤器,将原始url放入请求属性。

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

另见 servlet 2.3功能文章

这篇关于如何在请求调度程序转发后获取原始页面url / uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆