web.xml 404 redirect to servlet, how to get the original URI?

后端 未结 1 1591
孤城傲影
孤城傲影 2020-12-05 15:48

I\'m redirecting 404 errors to a servlet via the following in my web.xml.


    404
    

        
1条回答
  •  不知归路
    2020-12-05 16:44

    Yes, it's available as a request attribute with the name javax.servlet.forward.request_uri, which is keyed by RequestDispatcher#FORWARD_REQUEST_URI. The error page location is namely invoked by a simple RequestDispatcher#forward() call.

    So, you can get it as follows in servlet:

    String originalUri = request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
    

    or in EL:

    Original URI: ${requestScope['javax.servlet.forward.request_uri']}

    0 讨论(0)
提交回复
热议问题