IntelliJ Java IDE
The moose likes BEA/Weblogic and the fly likes Error handling Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Reply Bookmark "Error handling" Watch "Error handling" New topic
Author

Error handling

Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1061
I�m using WL 6.0 SP2.
My web.xml has the following declaration -
<web-app>
....
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>index.html</location>
</error-page>
.....
<web-app>

In my JSP program I have the following -
<%
int i = 4/0;
out.print("<p><b>Hello World5!</b>");
%>
When running the JSP, I get HTTP 500 error message.
The console does inform me that the servlet failed with java.lang.ArithmeticException.
Any idea why I don't get the index.html instead of the HTTP 500 error screen?
Thanks,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Joe McGuire
Ranch Hand

Joined: Mar 19, 2001
Posts: 293
Okay, I played around with this for awhile, and finally got it to work. Add a "/" before index.html in your web.xml file:
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/index.html</location>
</error-page>
I don't know why it should matter, but it did!
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1061
Thanks Joe!
But for some reason the following works fine -
(It also works with /index.html)
<error-page>
<error-code>404</error-code>
<location>index.html</location>
</error-page>
Is it an inconsistency between the two elements - error-code and exception-type?
Thanks,
Dan
Joe McGuire
Ranch Hand

Joined: Mar 19, 2001
Posts: 293
I noticed that. Screwy, ain't it!
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1061
Hi,
Now my web.xml starts like this -
<web-app>
<error-page>
<error-code>404</error-code>
<location>\index.html</location>
</error-page>
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/index.html</location>
</error-page>
The service method in a servlet of this web app is -
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{

res.sendError(404);
}
When running this servlet, the request times out - No response at all.
When taking the error-code section from web.xml, the response is the expected 404 error message.
Taking out -
<error-page>
<error-code>404</error-code>
<location>\index.html</location>
</error-page>
Any ideas?
Thanks,
Dan
Joe McGuire
Ranch Hand

Joined: Mar 19, 2001
Posts: 293
It should be forward slash index.html (/index.html) - you have backwards slash (\index.html) - or is that just a typo?
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1061
Just a typo.
The point is that the combination of -
<error-page>
<error-code>404</error-code>
<location>/index.html</location>
</error-page>
and the res.sendError(404) statement seems to confuse WL.
 
 
subject: Error handling
 
Threads others viewed
configuring error pages in DD
error-page!!!
error-page in DD
pageContext.exception is not executing
error-page!!!
IntelliJ Java IDE