• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overriding <exception-type> tag in web.xml

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following code:

try
{ ... }
catch ( IOException ie )
{ ... }
catch ( Exception e )
{ ... }

Here, in case of IOException, the first 'catch' block will execute whereas in case of any other exception, the second 'catch' block will execute. Can we do the same thing in 'web.xml' ( Deployment Descriptor for any servlet )?? Suppose, I want to redirect the user to one.jsp if ArithmeticException occurs and redirect the user to two.jsp if any other exception occurs, how would I configure my 'web.xml'?

This is what I tried which is not working out:

<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/one.jsp</location>
</error-page>

<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/two.jsp</location>
</error-page>

Any help is greatly appreciated... Thanks.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sanket Apte wrote:
This is what I tried which is not working out:



Working for me. and Welcome to javaranch
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and i guess, you tried in IE browser if yes. tools---->internetoption-->advance-->uncheck the Show http friendly messages
 
Sanket Apte
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the answers. But, it is still not working for me. I tried in IE as well as in Google Chrome. This is my code....

web.xml
================================================================
<?xml.... >

<servlet> ... </servlet>

<servlet-mapping> ... </servlet-mapping>

<error-page>
<error-code>404</error-code>
<location>/PageNotFoundErrors.jsp</location>
</error-page>

<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/ArithmeticErrors.jsp</location>
</error-page>

<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/OtherErrors.jsp</location>
</error-page>

</web-app>

jsp page:
====================================================================================
<body>

<%!
public void recursion() // This function calls itself countless times and finally produces a StackOverflowError
{
recursion();
}
%>

Enter 1 for ArithmeticException, 2 for 'Page not found', 3 for 'Other errors'... <br />
<form method = "POST">
<input type = "text" name = "option" />
<br /><br />
<input type = "submit" />
</form>

<c:if test = "${pageContext.request.method == 'POST'}">
<c:choose>
<c:when test = "${param.option == '1'}" >
<% int i = 10%0; // This code generates an ArithmeticException %>
</c:when>

<c:when test = "${param.option == '2'}" >
<c:redirect url = "/NonExistentPage.jsp" />
</c:when>

<c:when test = "${param.option == '3'}">
<% recursion(); %>
</c:when>

<c:otherwise>
<c:out value = "There are no errors..." />
</c:otherwise>
</c:choose>
</c:if>

</body>

=================================================================================

Everytime I run this, no matter what error is generated, I am always redirected to OtherErrors.jsp
What can be the solution?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
think you find the solution here http://docs.codehaus.org/display/JETTY/How+to+Create+Custom+Error+Pages
context file configuration.


 
Sanket Apte
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Mike,

Thanks a lot for help, but the link you have provided is for Jetty server. I use Tomcat 6.x. How do I configure my web.xml for Tomcat?
 
expectation is the root of all heartache - shakespeare. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic