Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception implicit object even though page directive is not present

 
Luis Centeno
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks...

I am going through JSP used as error pages. I created one example in order to verify exception implicit object behavior and I have one doubt...

I created a jsp...



and error page specificError.jsp


I got following output...

This is a specific error
Exception: javax.servlet.jsp.JspTagException: In URL tags, when the "context" attribute is specified, values of both "context" and "url" must start with "/".
Message: In URL tags, when the "context" attribute is specified, values of both "context" and "url" must start with "/".
StackTrace: [Ljava.lang.StackTraceElement;@c8570c

I know why the exception is thrown, but according to HFSJ, exception object should not be available when page directive does not include isErrorPage attribute, in this case exception is giving me information about the exception though...

Any idea will be appreciated...Thanks in advance
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

but according to HFSJ, exception object should not be available when page directive does not include isErrorPage attribute, in this case exception is giving me information about the exception though...


Yes Hf said "exception" object is not available but "pageContext" is available , you are accessing exception through pageContext.

try doing this in your jsp and tell us the result.

 
Luis Centeno
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Parth,

Thanks for your reply. I did exactly what you said and it did not work either. It did not work as exception is not an EL implicit object and it is not bound as an attribute in any scope (please correct me if I am wrong). I think you might referred to exception implicit object from scripting which I accessed with below code...



It showed the information as I expected...

Please let me know if I am missing something...

Regards
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Luis,

What server are you testing it?

I am getting errors on Tomcat 5.5 and Jboss:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 17 in the jsp file: /jsp/error.jsp
Generated servlet error:
exception cannot be resolved



According to the spec
Indicates if the current JSP page is intended to be the URL
target of another JSP page's errorPage.
If true, then the implicit script language variable exception is
defined and its value is a reference to the offending
Throwable from the source JSP page in error.
If false then the exception implicit variable is unavailable,
and any reference to it within the body of the JSP page is
illegal and shall result in a fatal translation error.
Default is false.

So you have to use scriptlets in order to get the error


Regards,
Frits
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Oh yes Luis I was sleeping . yes i referred to

1. Exception: <%=exception.getMessage()%>

2. StackTrace: <%=exception.getStackTrace()%>

these only.

Frits is right here , which server are you testing on?
As the spec says its unavailable , so beleive that only.
 
Luis Centeno
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frits...

Yes, you are right. I forgot to mention that I needed to add page directive with isErrorPage attribute set to true in order to get JSP implicit object exception. When I removed the page directive, it errored out as you say...

So, this means that exception object will always be available through pageContext implicit object in EL regardless page is or is not a designed error page?

Thanks
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, this means that exception object will always be available through pageContext implicit object in EL regardless page is or is not a designed error page?


Yes, a little bit further in the specs you will find the answer:
JSP.1.4.3 Using JSPs as Error Pages
...
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.
...

Regards,
Frits
 
Luis Centeno
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, this seems to be a tricky part of JSPs. I will keep this on my mind for the exam...

Thanks Parth and Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic