exception implicit object even though page directive is not present
Luis Centeno
Ranch Hand
Joined: Jul 31, 2009
Posts: 46
posted
0
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
SCJP 6 | SCWCD 5
Parth Twari
Ranch Hand
Joined: Jan 20, 2010
Posts: 163
posted
0
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.
Parth Tiwari
| Pursuing Bachelor of Engineering | OSUM Club Leader | SCJP 6 | SCWCD 5 |...
Luis Centeno
Ranch Hand
Joined: Jul 31, 2009
Posts: 46
posted
0
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...
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
This message was edited 1 time. Last update was at by Frits Walraven
Parth Twari
Ranch Hand
Joined: Jan 20, 2010
Posts: 163
posted
0
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
Joined: Jul 31, 2009
Posts: 46
posted
0
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
This message was edited 1 time. Last update was at by Luis Centeno
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
Joined: Jul 31, 2009
Posts: 46
posted
0
OK, this seems to be a tricky part of JSPs. I will keep this on my mind for the exam...
Thanks Parth and Frits
subject: exception implicit object even though page directive is not present