根据原始请求的 URL 显示不同的 Tomcat 错误页面
我想使用Tomcat的错误页面指令来显示各种不同的错误页面以响应各种类型的异常。 但是,我希望显示的错误页面具有不同的样式和内容,具体取决于导致错误的原始请求 URL。
具体来说,我的网络应用程序有一个管理部分和一个用户部分。 错误页面在样式和菜单方面都应该有所不同。 区分给定页面所在部分的最可靠方法是查找 URL 中的字符串。 我想将 Tomcat 错误页面指向一个 servlet,它将解析 URL 并重定向到适当样式的错误页面。
那么 1) 是否可以使用错误页面或其他机制将错误重定向到 servlet 而不是 JSP? (如果没有,我可以在 JSP 中执行我想象的操作吗?)
2)一旦进入 servlet,我可以确定导致错误的请求 URL(request.requestURI 似乎不起作用) -- 它指向错误 JSP 本身的位置)。
I would like to use Tomcat's error-page directive to display various different error pages in response to various types of exceptions. However, I want the error page displayed to have different styling and content depending on the original request URL that resulted in the error.
Specifically, I have an admin part of my web application, and a user part. The error pages should be different, both in terms of styling and menus. The most reliable way to distinguish which part a given page is in is by looking for strings in the URL. I'd like to point the Tomcat error-page to, say, a servlet that would parse the URL and redirect to the appropriately styled error page.
So 1) is it possible to use error-page, or some other mechanism, to redirect errors to a servlet rather than a JSP? (And if not, can I do what I'm imagining within a JSP?)
and 2) once I'm in my servlet, can I determine the request URL that led to the error (request.requestURI doesn't appear to work -- it points to the location of the error JSP itself).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
获取原始 requestURI,
您可以从您通过
web.xml
中的
注册的错误 jsp 中请参阅 http://java.sun.com/j2ee/1.4/docs/api/javax /servlet/jsp/ErrorData.html 了解更多信息。
至于使用 servlet,您可以在错误 jsp 中使用
转发到您选择的 servlet。You can get the original requestURI from
In your error jsp that you register via
<error-page>
in yourweb.xml
See http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/ErrorData.html for more information.
As for using a servlet, you can probably use a
<jsp:forward>
inside the error jsp to forward to a servlet of your choosing.Tomcat 的错误页面是显示应用程序错误的最后手段(以防万一您的错误页面实际上失败)。通常您应该(我建议)构建自己的错误页面,您可以在非技术视图中显示错误(默认情况下) )和技术视图(如果用户愿意)以适合您的用户的方式。
Tomcat's error page is the last resort for showing application errors(just in case your error page fails actually).Usually you should(I would recommend) to build your own error page where you can display errors in a non-technical view(by default) and technical view(if the user wants) in such a manner that is suitable for your users.