Jetty中未显示自定义错误页面

时间:2016-07-20 09:21:45

标签: jsp exception-handling jetty custom-error-pages jetty-9

我希望在JSP解析和运行时显示Exception。

但不行。我错了什么?

我知道在页面上使用errorPage指令是解决我的问题的解决方案之一。但我不想编辑所有文件。

我像这样编辑了web.xml。

的web.xml

 <error-page>
   <exception-type>java.lang.Throwable</exception-type>
   <location>/exception.jsp</location>
 </error-page>

我的exception.jsp就在这里。

exception.jsp

<%@ page isErrorPage="true" language="java" contentType="text/html;charset=SHIFT_JIS" pageEncoding="SHIFT_JIS" %>
<h1>
  <%= exception %>
</h1>
<pre>
  <% exception.printStackTrace(new java.io.PrintWriter(out)); %>
</pre>

发生异常jsp就在这里。

index.jsp

<%@ page contentType="text/html; charset=SJIS" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head></head>
  <body>
    <% String a = null; a.toString(); %> 
  </body>
</html>

ENV

Servlet引擎 3.1

JSP引擎 2.3

Application Server 码头/ 9.2.15.v20160210

来自码头日志的例外

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 6

3: <html>
4:   <head></head>
5:   <body>
6:     <% String a = null; a.toString(); %>
7:   </body>
8: </html>


Stacktrace:
        at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)
[...] 
Caused by: java.lang.NullPointerException
        at org.apache.jsp.index_jsp._jspService(index_jsp.java:572)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
        ... 63 more

1 个答案:

答案 0 :(得分:-1)

我曾经使用过这种错误处理方式。但我不确定您是否可以使用* .jsp页面作为错误页面位置。它不一定是Servlet吗?

<!-- servlet definition -->
<servlet>
    <servlet-name>ErrorHandler</servlet-name>
    <servlet-class>ErrorHandler</servlet-class>
</servlet>
<error-page>
   <exception-type>java.lang.Throwable</exception-type >
   <location>/ErrorHandler</location>
</error-page>
相关问题