| Author |
using isErrorPage page Directive PRoblem
|
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
Head First Servlet and JSP
2nd Edition
Using JSTl
pg-471
Note:exception implicit object is avaialble only to error pages with explicilty defined page directive:
<%@ page isErrorPage="true" %>
error.jsp
defined in a servlet
defined in web.xml
The Output of Error.jsp is
TRY AGAin Default
But as said in Head First servlets and JSp,the pageContext must have access to exception and should give the error message instead of the default value.
|
OCPJP 6.0 93%
OCPJWCD 5.0 98%
|
 |
Niiraj Patel
Ranch Hand
Joined: Sep 17, 2011
Posts: 34
|
|
Hi Mohit,
It might be problem with your container.
Which container does you use?
I simulated things and in my case its working fine in apache-tomcat-5.5.33
Please refer below thread which is closely related to your problem.
http://www.coderanch.com/t/287342/JSP/java/pageContext-getException-always-null
Thanks,
Nirraj Patel
|
 |
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
I am using Tomcat v5.5 .
Please provide solution to resolve the issue.
|
 |
Niiraj Patel
Ranch Hand
Joined: Sep 17, 2011
Posts: 34
|
|
Hi Mohit,
If you want to use servlet exception object with page directive isErroPage="false",
Quick Fix:
The thread I mentioned in previous post said:
Earliear implementor of pageContext.getException() had below line.
Now, In newer version, it is :
The Jsp Fact : JSP.1.4.3
If a page has isErrorPage set to true, then the "exception" implicit
scripting language variable of that page is initialized. The
variable is set to the value of the javax.servlet.error.exception request attribute
value.
So, You can get Throwable object from request attribute "javax.servlet.jsp.jspException".
e.g.
Thanks,
Niraj Patel
|
 |
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
modified error.jsp
I have added the code you said but it gave an exception
Exception:
Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.Error_jsp._jspService(Error_jsp.java:71)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:659)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:364)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:285)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:662)
Oct 9, 2011 12:36:43 PM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[errorCode=405, location=/Error.jsp]
org.apache.jasper.JasperException: Exception in JSP: /Error.jsp:14
11: TRY AGAin
12: <c: out value="${pageContext.exception}">Default</c: out>
13: <%Throwable error = (Throwable) request.getAttribute("javax.servlet.error.exception");
14: error.getMessage();
15: %>
16:
17: </body>
I wish to get the exception using EL
and not through scripets
|
 |
Niiraj Patel
Ranch Hand
Joined: Sep 17, 2011
Posts: 34
|
|
Mohit,
The root cause of error is you got NULL from request.getAttribute("javax.servlet.error.exception");
Try request.getAttribute("javax.servlet.jsp.jspException"); instead of request.getAttribute("javax.servlet.error.exception");
print your exceptions first. .
like :
Can you tell me the exact version of tomcat container.. ??
And
Also try your example with newer version. .
Regards,
Niraj
|
 |
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
I am using Apache Tomcat Version 5.5.31.
Got null in the browser output for both of the statements.
the newer version:
Multiple annotations found at this line:
JspRuntimeLibrary cannot be resolved
I have the jasper-compiler.jar and jasper-runtime.jar in the web-inf/lib folder.
|
 |
Niiraj Patel
Ranch Hand
Joined: Sep 17, 2011
Posts: 34
|
|
You dont have to write
<%JspRuntimeLibrary.getThrowable(request); %> in your jsp.
Download tomcat version 5.5.34 and just paste all your code as it is in old version(jsp+servlet+web.xml). and run your example in new tomcat.
e.g.
your error.jsp should be.
Regards,
Niraj
|
 |
 |
|
|
subject: using isErrorPage page Directive PRoblem
|
|
|