zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    团队作业(三)
    第四章学习笔记
    2.3.1测试
    缓冲区溢出漏洞实验
    第三章学习笔记
    团队作业(二)
    第十一章学习笔记
    第7,8章自学笔记
    stat命令实现—mystat
    第五章学习笔记
  • 原文地址:https://www.cnblogs.com/suhfj-825/p/8215324.html
Copyright © 2011-2022 走看看