Search code examples
javajsppage-directives

isErrorPage="false" is ignored by container


Getting to the point, I have .jsp page and error page, well if there is something goes wrong with the first one, the error page should turn up then, now i don't want the first page to redirect to the error page anymore, by assigning false to isErrorPage attribute at the error page, the first page should display that stupid exception trace, however the first page keeps redirecting to the error page, here is my simple Error page code :

 <%@page contentType="text/html" pageEncoding="UTF-8" isErrorPage="false"%>
 <!DOCTYPE html>
 <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
      <body>
       <h1>guess what ? this is supposed to be an error page</h1>
     </body>
</html>

here's the first page I've been talking about :

 <%@page contentType="text/html" pageEncoding="UTF-8" errorPage="anotherErrorPage.jsp" %>
   <!DOCTYPE html>
 <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <title>JSP Page</title>
    </head>
  <body>
      <h1>Hello World!</h1>

      <% int i = 3/0;%>
  </body>
</html>

thanks a zillion .


Solution

  • isErrorPage="false" does not stop you to redirect error page. As long as you specified errorPage in the first JSP, it will redirect to its errorpage. In you example it redirects to "anotherErrorPage".

    isErrorPage attribute decides whether the implicit object exception will be available or not. During JSP to Servlet conversion, In service() method, based on this attribute exception object would be defined. If you set false you can't use exception object in that page.If you set true exception object will be there and you can use it

    In your case If you want to show the exception you have todo either of the below,
    1. In anotherErrorPage, define isErrorPage="true" and display or catch the exception by implicit object "exception".
    2.Remove errorPage attribute in first jsp page.