Custom error page - get originally requested URL

后端 未结 2 2029
说谎
说谎 2020-12-20 23:47

Problem

This is a follow-up to yesterday\'s (unanswered) question (see here) as I try to find an alternative approach.

I added the basic

2条回答
  •  难免孤独
    2020-12-21 00:29

    The is under the covers served by a RequestDispatcher#forward() call. All details of the original request are available as request attribues which are keyed by the keys as identified by RequestDispatcher#FORWARD_XXX constants:

    • FORWARD_CONTEXT_PATH: "javax.servlet.forward.context_path"
    • FORWARD_PATH_INFO: "javax.servlet.forward.path_info"
    • FORWARD_QUERY_STRING: "javax.servlet.forward.query_string"
    • FORWARD_REQUEST_URI: "javax.servlet.forward.request_uri"
    • FORWARD_SERVLET_PATH: "javax.servlet.forward.servlet_path"

    You as starter should know that all request attributes are in EL available via the implicit EL object #{requestScope}.

    So, all with all, this should do in the view:

    Unfortunately, the page you requested, #{requestScope['javax.servlet.forward.request_uri']} does not exist

    And equivalently, this should do in the bean, if necessary:

    String forwardRequestURI = externalContext.getRequestMap().get(RequestDispatcher.FORWARD_REQUEST_URI);
    

提交回复
热议问题