aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes using ${exception.message} Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "using ${exception.message}" Watch "using ${exception.message}" New topic
Author

using ${exception.message}

SanjayKrishna Sharma
Greenhorn

Joined: Mar 26, 2008
Posts: 7
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!!!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

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}


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 460

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?


Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
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'.
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119

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" %>



SCJP 5 , SCWCD 5
SanjayKrishna Sharma
Greenhorn

Joined: Mar 26, 2008
Posts: 7
Thanks Ankit, Sai, Chinmaya and Priya.

I understood my mistake.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using ${exception.message}