获取导致404的请求页面的URL

ale*_*oco 6 jsp

如何获取导致404错误的请求页面的URL?

例如,我输入http://example.com/path/does/not/exist/index.jsp 我已经有了一个自定义404页面,但我如何检索上面提到的URL以便我可以显示它的消息类似于"网址http://example.com/path/does/not/exist/index.jsp不存在"?

Boz*_*zho 9

如果使用forward转到错误页面,则可以获取原始请求URL

request.getAttribute("javax.servlet.forward.request_uri")
Run Code Online (Sandbox Code Playgroud)

或EL

${requestScope['javax.servlet.forward.request_uri']}
Run Code Online (Sandbox Code Playgroud)

  • 实际上,"<error-page>"是每个定义由前向显示. (2认同)