JSP Page Exception Detection Through RequestDispatcher

I have a JSP page with the specified error page. I call the page from the servlet through:

RequestDispatcher rd = ctx.getRequestDispatcher( jspPage ); rd.include( req, res ); 

How to determine if a jsp page is being forwarded to a page with an error or not? I want to handle exceptions differently, but no exception is thrown. And unfortunately, I cannot change the JSP page or the error page.

Edit:

I think something like this might work after the line include (), any thoughts?

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

Add this to your web.xml file:

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

Assuming you have a printout of the stack trace or a similar way to notify the user of a problem that occurred on the error.html page.

0
source

Source: https://habr.com/ru/post/1334590/


All Articles