File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes OCPJWCD - Doubt about errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "OCPJWCD - Doubt about errors" Watch "OCPJWCD - Doubt about errors" New topic
Author

OCPJWCD - Doubt about errors

Erick Macedo
Greenhorn

Joined: Feb 17, 2013
Posts: 14
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

Joined: Sep 13, 2007
Posts: 2228
    
    7

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()



K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Erick Macedo
Greenhorn

Joined: Feb 17, 2013
Posts: 14
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
Bartender

Joined: Apr 07, 2010
Posts: 1624
    
  23

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
     
    subject: OCPJWCD - Doubt about errors
     
    Similar Threads
    How to get exception object on error page with EL?
    HFSJ Page 471:
    Page 461
    page isErrorPage="false"
    implicit objects