aspose file tools*
The moose likes JSP and the fly likes runtime exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "runtime exceptions" Watch "runtime exceptions" New topic
Author

runtime exceptions

bharath phatak
Greenhorn

Joined: Jul 28, 2011
Posts: 7
I am trying handle the runtime exceptions globally throughout the application. I am using struts 1.1, I did the following changes in web.xml
<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>/error.jsp</location>
</error-page>

Also tried having the fix in struts-config.xml
<global-exceptions>
<exception type=" java.lang.RuntimeException "
key="sample.key"
path="/error.jsp"/>
</global-exceptions>

But Whenever the runtime exception(like javax.servlet.jsp.JspException) occurs the error.jsp is not getting displayed instead the entire stacktrace is shown which should be avoided. Please suggest what is going wrong or if there is any other solution to avoid the stacktrace shown on UI.

Any help is much appreciated
Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
I hope your error.jsp has its page attribute isErrorPage set to true
bharath phatak
Greenhorn

Joined: Jul 28, 2011
Posts: 7
Yes the error.jsp has the following attribute <%@ page isErrorPage="true" contentType="text/plain"%>.

Should i be setting any other value?

Thanks.
Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
bharath phatak wrote:Yes the error.jsp has the following attribute <%@ page isErrorPage="true" contentType="text/plain"%>.

Should i be setting any other value?

Thanks.


...and the page attribute errorPage is having value error.jsp on the jsp where the Exception object is getting created
bharath phatak
Greenhorn

Joined: Jul 28, 2011
Posts: 7
If the exception is thrown in sample.jsp, then should we have this line in the jsp <%@ page errorPage="/error.jsp"%>.
There are many JSP's in the application, i dont want to touch all the JSP's ,
is there any other way handle the exceptions without touching upon all the JSP's in struts 1.1
Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
bharath phatak wrote: If the exception is thrown in sample.jsp, then should we have this line in the jsp <%@ page errorPage="/error.jsp"%>.
There are many JSP's in the application, i dont want to touch all the JSP's ,
is there any other way handle the exceptions without touching upon all the JSP's in struts 1.1


I am not very sure about Struts 1.1 Bharath but the configuration you have done in the struts-congfig.xml seems to be right only I feel you should define action for all Jsp's as well...
bharath phatak
Greenhorn

Joined: Jul 28, 2011
Posts: 7
Thanks anyways.

hope i get a solution in this forum.
bharath phatak
Greenhorn

Joined: Jul 28, 2011
Posts: 7
Ashutosh,
If we have to include <%@ page errorPage="/error.jsp"%>. and <%@ page isErrorPage="true" contentType="text/plain"%>. , then we should not make any changes to web.xml or struts-config.xml?
Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
bharath phatak wrote:Ashutosh,
If we have to include <%@ page errorPage="/error.jsp"%>. and <%@ page isErrorPage="true" contentType="text/plain"%>. , then we should not make any changes to web.xml or struts-config.xml?


I think so... but I may be wrong, you better try that out and let me know as well.
bharath phatak
Greenhorn

Joined: Jul 28, 2011
Posts: 7
sure. I will try and let you know
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: runtime exceptions
 
Similar Threads
strange error-page problem?
Global excpetion-getting print stack trace?
Error Page
JSF : redirect errors to error page
JSF 2.0 exception handling - Is it necessary to catch the exceptions in the Bean classes ?