什么是将Exception从Servlet重定向到默认错误JSP的正确技巧? [英] what's the right technique to redirect an Exception from a Servlet to a default error JSP?

查看:120
本文介绍了什么是将Exception从Servlet重定向到默认错误JSP的正确技巧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个默认的错误JSP页面,当servlet抛出异常时会显示该页面,该页面将显示堆栈跟踪..



如何做我这样做?是否有正确的技术(由API提供)或我必须手动完成?我的意思是,将异常作为属性抛出,然后自己处理它?<​​/ p>

谢谢

解决方案

您可以在web.xml中配置要处理的异常类型和JSP页面,例如:

 <错误页> 
< exception-type> UnhandledException< / exception-type>
< location> UnhandledException.jsp< / location>
< / error-page>

这里有关于这个主题的Oracle文章:



http://www.oracle .com / technology / sample_code / tech / java / codesnippet / servlets / HandlingServletExceptions / HandlingServletExceptions.html


I need to have a default error JSP page which is shown when an exception is thrown by the servlet, and that page will show the stacktrace..

How do I do that?? is there a right technique (provided by the API) or I have to do it manually?? I mean, sending the exception thrown as an attribute and then dealing with it by myself??

Thanks

解决方案

You can configure the exception type and the JSP page to handle in web.xml, e.g:

<error-page>
       <exception-type>UnhandledException</exception-type>
       <location>UnhandledException.jsp</location>
</error-page>

There's an Oracle article here on the subject:

http://www.oracle.com/technology/sample_code/tech/java/codesnippet/servlets/HandlingServletExceptions/HandlingServletExceptions.html

这篇关于什么是将Exception从Servlet重定向到默认错误JSP的正确技巧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆