zoukankan      html  css  js  c++  java
  • 获取来自jsp errorpage 的exception 对象

    1. 在web.xml 中配置(全局)

      <error-page>
      <exception-type>javax.servlet.ServletException</exception-type>
      <location>/error/logJspExceptionToFile.do</location>
      </error-page>

    或在jsp 页面中配置 (单页面)

    <%@ page errorPage="/error/logJspExceptionToFile.do" %>

    2.在servlet 中处理传过来的异常.

    @WebServlet("/error/logJspExceptiontoFile.do")
    public class AppExceptionHandler extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            processError(request, response);
        }
    
        protected void doPost(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            processError(request, response);
        }
    
        private void processError(HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            // Analyze the servlet exception
            Throwable throwable = (Throwable) request
                    .getAttribute("javax.servlet.error.exception");
            Integer statusCode = (Integer) request
                    .getAttribute("javax.servlet.error.status_code");
            String servletName = (String) request
                    .getAttribute("javax.servlet.error.servlet_name");
            if (servletName == null) {
                servletName = "Unknown";
            }
            String requestUri = (String) request
                    .getAttribute("javax.servlet.error.request_uri");
            if (requestUri == null) {
                requestUri = "Unknown";
            }
        }
    }
  • 相关阅读:
    SQL优化总结(转)
    ORA-04030: 在尝试分配...字节(...)时进程内存不足的原因分析解决方法
    MyEclipse 在线安装SVN插件
    jboss+ejb entityManager操作数据库
    struts2标签#、%、$取值
    ejb+weblogic布署(转)
    ejb+jboss集群(转)
    myeclipse配置jboss(转载)
    list-列表练习
    python-循环小练习
  • 原文地址:https://www.cnblogs.com/predisw/p/4949484.html
Copyright © 2011-2022 走看看