error.jsp错误页面跳转,统一异常处理


常见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">
         遇到错误,&nbsp;<span id="secondes">5</span>&nbsp;秒后将自动跳转,立即跳转请点击&nbsp;
         <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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM