Forums Register Login

using ${exception.message}

+Pie Number of slices to send: Send
while giving mock exam I got below question and I am unable to understand why
${exception.message} is not valid answer?

Question:- A JSP page myerror.jsp has been invoked as a result of an exception from another JSP page.
How can you print the message contained in the exception instead of displaying the whole stack trace in myerror.jsp?

Why ${exception.message} is not correct.

Thanks!!!
+Pie Number of slices to send: Send
Sanjay there is no object named exception in EL. That implicit object is only available in scripting tags (in error pages of course). In EL, to get the exception object in an error page, you'll have to go through the pageContext object i.e. ${pageContext.exception.message}
+Pie Number of slices to send: Send
 

Ankit Garg wrote:Sanjay there is no object named exception in EL. That implicit object is only available in scripting tags (in error pages of course). In EL, to get the exception object in an error page, you'll have to go through the pageContext object i.e. ${pageContext.exception.message}



${pageContext.exception.message} shows exception message if the JSP is marked with <%@ page isErrorPage="true" %>.
If not, the implicit exception is not available to pageContext.
Am I correct?
+Pie Number of slices to send: Send
Hi Sai.

${pageContext.exception.message} shows exception message if the JSP is marked with <%@ page isErrorPage="true" %>.
If not, the implicit exception is not available to pageContext.
Am I correct?



No need to declare page directive

<%@ page isErrorPage="true" %>

in jsp, if we use EL. Here 'pageContext' object always available for jsp. Through which we can get 'exception' object and 'message'.
+Pie Number of slices to send: Send
 


if the JSP is marked with <%@ page isErrorPage="true" %>.
If not, the implicit exception is not available to pageContext.
Am I correct?



its true only for jsp implicit object exception ,

<%= exception.getMessage() %>

you can use the implicit object exception ,
only if you have explicity defined page directive : <%@ page isErrorPage="true" %>


+Pie Number of slices to send: Send
Thanks Ankit, Sai, Chinmaya and Priya.

I understood my mistake.
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2199 times.
Similar Threads
JSP page display problem
exception object and EL
implicit objects are available to the jsp page
Unexpected Error Logging
handle exception in servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:10:11.