Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过RequestDispatcher检测JSP页面中的异常_Java_Jsp_Servlets - Fatal编程技术网

Java 通过RequestDispatcher检测JSP页面中的异常

Java 通过RequestDispatcher检测JSP页面中的异常,java,jsp,servlets,Java,Jsp,Servlets,我有一个指定了错误页面的JSP页面。我通过以下方式从servlet调用页面: RequestDispatcher rd = ctx.getRequestDispatcher( jspPage ); rd.include( req, res ); 如何检测jsp页面是否转发到错误页面?我希望以不同的方式处理异常,但不会引发异常。不幸的是,我无法修改JSP页面本身或错误页面 编辑: 我在想,在include()行之后,类似的东西可能会起作用,有什么想法吗 Object errorServletNa

我有一个指定了错误页面的JSP页面。我通过以下方式从servlet调用页面:

RequestDispatcher rd = ctx.getRequestDispatcher( jspPage );
rd.include( req, res );
如何检测jsp页面是否转发到错误页面?我希望以不同的方式处理异常,但不会引发异常。不幸的是,我无法修改JSP页面本身或错误页面

编辑:

我在想,在include()行之后,类似的东西可能会起作用,有什么想法吗

Object errorServletName = req.getAttribute( "javax.servlet.error.servlet_name" );
if ( errorServletName != null ) 
{ there was an error in the JSP... }

将以下内容添加到web.xml文件:

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

java.lang.Throwable
/error.html

假设您有堆栈跟踪打印输出或类似的方式通知用户他们在error.html页面遇到的问题。

将以下内容添加到web.xml文件:

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

java.lang.Throwable
/error.html

假设您有堆栈跟踪打印输出或类似的方式来通知用户他们在error.html页面上遇到的问题。

您希望在何处检测此问题?在给定示例中的
include()
行之后?为什么JSP抛出异常?这表示您是否意识到现在显示错误页面可能太晚了?即,当响应已经提交时,它抛出异常。无论如何,是否允许您更改
web.xml
中的
条目?如果是这样,那么这就是答案。我想在示例中的include()行之后检测它。JSP页面指定了一个errorPage,因此当出现异常时,它会被踢到error.JSP,这通常是正常的。但是在include()行之后,我需要执行res.getContents()并对输出进行其他处理…我需要将错误页面输出作为一个特殊情况处理,因此我希望有一种方法可以检测它是否被转发到错误页面。希望这能澄清…你到底想在哪里发现这个?在给定示例中的
include()
行之后?为什么JSP抛出异常?这表示您是否意识到现在显示错误页面可能太晚了?即,当响应已经提交时,它抛出异常。无论如何,是否允许您更改
web.xml
中的
条目?如果是这样,那么这就是答案。我想在示例中的include()行之后检测它。JSP页面指定了一个errorPage,因此当出现异常时,它会被踢到error.JSP,这通常是正常的。但是在include()行之后,我需要执行res.getContents()并对输出进行其他处理…我需要将错误页面输出作为一个特殊情况处理,因此我希望有一种方法可以检测它是否被转发到错误页面。希望澄清。。。