赞
踩
<error-page> <error-code>400</error-code> <location>/400.html</location> </error-page> <error-page> <error-code>404</error-code> <location>/404.html</location> </error-page> <error-page> <error-code>500</error-code> <location>/error.jsp</location> </error-page>
<%@page contentType="text/html;charset=Big5" isErrorPage="true"%><html><head><title>出现错误</title></head><body> <H1>错误:</H1><%=exception%> <H2>错误内容:</H2> <% exception.printStackTrace(response.getWriter()); %></body></html>
因为这个页面调用了exception内置对象,所以isErrorPage必须为true。
<error-page> <exception-type>javax.servlet.ServletException</exception-type> <location>/errorhandler.jsp</location></error-page>
不仅可以使用jsp内置exception对象来取得异常,也可以取得request中的attribute。例如:
<%@page contentType="text/html;charset=Big5" isErrorPage="true"%><html><head><title>错误信息</title></head><body> 错误码: <%=request.getAttribute("javax.servlet.error.status_code")%> <br> 信息: <%=request.getAttribute("javax.servlet.error.message")%> <br> 异常: <%=request.getAttribute("javax.servlet.error.exception_type")%> <br></body></html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。