How to know when the request is forwarded in a RequestWrapper object

前端 未结 1 630
失恋的感觉
失恋的感觉 2020-12-21 05:48

I am using a subclass of HttpServletRequestWrapper to do some translations on the request parameters, and I cache the translated values the first time they are

相关标签:
1条回答
  • 2020-12-21 06:35

    The original request URI is available as request attribute with the key RequestDispatcher.FORWARD_REQUEST_URI.

    String originalRequestURI = request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
    
    if (originalRequestURI != null) {
        // It was forwarded. Now get the query string as follows.
        String originalQueryString = request.getAttribute(RequestDispatcher.FORWARD_QUERY_STRING);
    }
    

    Note: in older Servlet API versions you need to hardcode the key instead.

    String originalRequestURI = request.getAttribute("javax.servlet.forward.request_uri");
    // ...
    
    0 讨论(0)
提交回复
热议问题