jsp错误页面404、500等异常捕获 深碍√TFBOYSˉ_ 2022-06-03 06:24 197阅读 0赞 首先在web.xml中配置: <error-page> <error-code>400</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>401</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>402</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>403</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>405</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>406</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>407</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>413</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>414</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/pages/common/exceptionError.jsp</location> </error-page> <error-page> <exception-type>java.lang.Exception</exception-type> <location>/pages/common/exceptionError.jsp</location> </error-page> 或者 <error-page> <exception-type>javax.servlet.ServletException</exception-type> <location>/pages/common/exceptionError.jsp </location> </error-page> exceptionError.jsp页面内容: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <title>出错啦</title> <script type="text/javascript"> function refresh() { if(self.frameElement.tagName=="IFRAME"){ // 页面在iframe中时处理 parent.showErrorMsg('<h2 align="center" style="font-size: 18px; color: red; "> 程序异常,请联系管理员 <br></h2>'); } } refresh(); </script> </head> <body> <input type="hidden" id="errorMsg" value="程序异常,请联系管理员"> <div id="errorMsgDiv"> <h2 align="center" style="font-size: 18px; color: red; "> 程序异常,请联系管理员<br><br> 错误码:<br><br> </h2> <h1 align="center" style="font-size: 60px; color: red;"> <%=request.getAttribute("javax.servlet.error.status_code")%> <br> </h1> <br> <br> <h2 align="center" style="font-size: 18px; color: gray; "> 信息: <%=request.getAttribute("javax.servlet.error.message")%> <br><br> 异常: <%=request.getAttribute("javax.servlet.error.exception_type")%> <br><br> </h2> </div> </body> </html>
还没有评论,来说两句吧...