常见web项目中会用倒计时然后跳转页面来处理异常
error.jsp关键代码:
<script language="javascript" type="text/javascript"> ???????????var timer; ???????????//启动跳转的定时器 ???????????function startTimes() { ???????????????timer = window.setInterval(showSecondes,1000); ???????????} ???????????var i = 5; ???????????function showSecondes() { ???????????????if (i > 0) { ???????????????????i--; ???????????????????document.getElementById("secondes").innerHTML = i; ???????????????} ???????????????else { ???????????????????window.clearInterval(timer); ???????????????????/*要跳转的请求*/ ???????????????????location.href = "toLogin.do"; ???????????????} ???????????} ???????????//取消跳转 ???????????function resetTimer() { ???????????????if (timer != null && timer != undefined) { ???????????????????window.clearInterval(timer); ???????????????????/*取消跳转的请求*/ ???????????????????location.href = "toLogin.do"; ???????????????} ???????????}</script> <body class="error_page" onload="startTimes();"> ????<h1 id="error"> ????????遇到错误, <span id="secondes">5</span> 秒后将自动跳转,立即跳转请点击 ????????<a ?href="javascript:resetTimer();">返回</a> ????</h1></body>
统一异常处理(两种方案)
方案一:
<error-page> ???????<exception-type>java.lang.Exception</exception-type> ???????<location>/WEB-INF/error.jsp</location><!--这里用绝对路径,因为不知道错误发生在哪里,无法写相对路径--></error-page>
方案二:
<error-page> ???????<exception-type>400|405|500</exception-type><!--如果需要每个都要配置,所以推荐方案一 --> ???????<location>/WEB-INF/error.jsp</location></error-page>
error.jsp错误页面跳转,统一异常处理
原文地址:https://www.cnblogs.com/suhfj-825/p/8215324.html