• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCPJWCD - Doubt about errors

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
     
    Poop goes in a willow feeder. Wipe with this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic