• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

using ${exception.message}

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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}
 
Ranch Hand
Posts: 463
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'.
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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


 
SanjayKrishna Sharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit, Sai, Chinmaya and Priya.

I understood my mistake.
    Bookmark Topic Watch Topic
  • New Topic