获取导致 404 的请求页面的 URL
如何获取导致 404 错误的请求页面的 URL?
例如,我输入 I go to http://example.com/path/does /not/exist/index.jsp 我已经有一个自定义 404 页面,但我将如何检索上述 URL,以便我可以使用类似于“The url http://example.com/path/does/not/exist/index.jsp 不存在”?
How would I get the URL of the page that was requested that caused the 404 error?
For example, I type I go to http://example.com/path/does/not/exist/index.jsp
I already have a custom 404 page but how would I go about retrieving the URL mentioned above so that I can display it with a message similar to "The url http://example.com/path/does/not/exist/index.jsp does not exist"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果使用forward跳转到错误页面,可以通过
或者通过EL获取原始请求URL
If forward was used to go to the error page, you can obtain the original request URL by
or by EL
我使用的是 JDK 8 和 GlassFish 4,并且
总是返回 null。最终起作用的是
我不确定为什么属性名称不同,但如果我列出的名称不适用于您的设置,这是我用来查找它的代码...
I'm using JDK 8 and GlassFish 4, and
always returned null for me. What eventually did work was
I'm not sure why the attribute name is different, but in case the name I listed doesn't work on your setup, here's the code I used to find it...