Get request URL in JSP which is forwarded by Servlet

后端 未结 8 1494
忘掉有多难
忘掉有多难 2020-11-29 22:27

How can I get request URL in JSP which is forwarded by Servlet?

If I run following code in JSP,

System.out.println(\"servlet path= \" + request.getSe         


        
8条回答
  •  醉话见心
    2020-11-29 22:59

    None of these attributes are reliable because per the servlet spec (2.4, 2.5 and 3.0), these attributes are overridden if you include/forward a second time (or if someone calls getNamedDispatcher). I think the only reliable way to get the original request URI/query string is to stick a filter at the beginning of your filter chain in web.xml that sets your own custom request attributes based on request.getRequestURI()/getQueryString() before any forwards/includes take place.

    http://www.caucho.com/resin-3.0/webapp/faq.xtp contains an excellent summary of how this works (minus the technical note that a second forward/include messes up your ability to use these attributes).

提交回复
热议问题