File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OCPJWCD - Doubt about errors

 
Erick Macedo
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning guys, one more question, now thanking everyone. HF book on page 471, the book makes clear the following.
the implicit exception object is available ONLY to error pages with a page directive explicitly defined: <% @ page isErrorPage = true%>

However to perform tests to determine this, is not this what happens, see:

Page generated -> ERROR: java.lang.ArithmeticException: / by zero
Guys, help me understand why the book says that the implicit exception object is available ONLY to error pages with a page directive explicitly set <% @ page isErrorPage = true%>?

thank you
 
K. Tsang
Bartender
Pie
Posts: 3228
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the exception tag is set to true in the @page declaration, the "exception" variable is explicitly available, such that you can do things like exception.printStackTrace()

 
Erick Macedo
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the exception tag is set to true in the @page declaration, the "exception" variable is explicitly available, such that you can do things like exception.printStackTrace()


Now understand, I believe that the book is wrong on this point, because the object that he should refer the exception is the former jsp: <% = exception.getMessage ()%>
and not the exception of pageContext.
On page 471 he made ​​clear that the $ {} pageContext.exception is available if the <% @ page isErrorPage = true%> which is not true, he should refer to the <% = exception%> because the $ {pageContext . exception} is available Independent of the directive <% @ page isErrorPage = true%>

thank you very much

K. Tsang
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2173
57
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Now understand, I believe that the book is wrong on this point, because the object that he should refer the exception is the former jsp: <% = exception.getMessage ()%>
and not the exception of pageContext.

I don't think the book is wrong. For me the Tomcat implementation doesn't follow the specs well on this point:

From JSP 2.2 specs
A JSP is considered an Error Page if it sets the page directive's isErrorPage attribute to true. If a page has isErrorPage set to true, then the "exception" implicit scripting language variable (see Table JSP.1-7) of that page is initialized. The variable is set to the value of the javax.servlet.error.exception request attribute value if present, otherwise to the value of the javax.servlet.jsp.jspException request attribute value (for backwards compatibility for JSP pages pre-compiled with a JSP 1.2 compiler).
In addition, an ErrorData instance must be initialized based on the error handler ServletRequest attributes defined by the Servlet specification, and made available through the PageContext to the page. This has the effect of providing easy access to the error information via the Expression Language For example, an Error Page can access the status code using the syntax ${pageContext.errorData.statusCode}.

In other words for:
  • for JSP's with scriptlets & expressions you can use the implicit variable "exception" (if your page is an errorPage)
  • for scriptless JSP's you can use EL to access the ErrorData object through the implicit variable "pageContext" (if your page is an errorPage)

  • Conclusion: there is no explicit paragraph in the specs stating that the ${pageContext.exception} should be available even in a page that is not an error page (not having a <% @ page isErrorPage = true%>) We can say that Tomcat is not entirely following the specs (it is providing exception information out of the context of an error page) and therefore book is correct on this point.

    Regards,
    Frits
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic