• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

OCPJWCD - Doubt about errors

 
Greenhorn
Posts: 16
  • 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
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • 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
  • 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
 
Creator of Enthuware JWS+ V6
Posts: 3341
303
Android Eclipse IDE Chrome
  • 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
     
    On top of spaghetti all covered in cheese, there was this tiny ad:
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic