This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Same exception different handle in tomcat4.1 and weblogic6.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Same exception different handle in tomcat4.1 and weblogic6.1" Watch "Same exception different handle in tomcat4.1 and weblogic6.1" New topic
Author

Same exception different handle in tomcat4.1 and weblogic6.1

Mellon Sun
Ranch Hand

Joined: Feb 20, 2003
Posts: 126
Wrox Book "Professional SCWCD Certification" said:
In a similar manner, the snippet given below will forward any ServletException or any subclass of
ServletException thrown by a servlet to the JSP page at location /error/error.jsp:
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/error/error.jsp</location>
</error-page>
My test.jsp:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
test
</title>
</head>
<body>
<h1>
<%
int random=(int)(5*Math.random());
//int random=0;
System.out.println("random="+random);
switch(random){
case 0 :{
System.out.println("case 0");
throw new java.io.IOException("mellon io excpeiton ");
}
case 1 : {
System.out.println("case 1");
throw new java.sql.SQLException("mellon sql exception ");
}
case 2 : {
System.out.println("case 2");
throw new java.sql.SQLWarning("mellon sql warning ");
}
case 3 : {
System.out.println("case 3");
throw new scwcd.exception.SubOfServletException("mellon SubOfServletException ");
}
case 4 : {
System.out.println("case 4");
throw new javax.servlet.ServletException("mellon ServletException ");
}
}
%>
</h1>
</body>
</html>
My web.xml:
<web-app>
<servlet>
<servlet-name>servlet1</servlet-name>
<servlet-class>scwcd.Servlet1</servlet-class>
</servlet>
<error-page>
<exception-type>java.io.IOException</exception-type>
<location>/errorpage/IOExceptionError.jsp</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/errorpage/SQLExceptionError.jsp</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLWarning</exception-type>
<location>/errorpage/SQLWarningError.jsp</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/errorpage/ServletExceptionError.jsp</location>
</error-page>
<error-page>
<exception-type>scwcd.exception.SubOfServletException</exception-type>
<location>/errorpage/SubOfServletExceptionError.jsp</location>
</error-page>
</web-app>
Of course I have five different error pages as expected.
In tomcat4.1 when the random is 1 and 2 ,
tomcat dispatch the exception to ServletExceptionError.jsp.
When the random is 0 ,tomcat dispatch the exception to
IOExceptionError.jsp.
When the random is 3 ,tomcat dispatch the exception to
SubOfServletExceptionError.jsp.
When the random is 4,tomcat dispatch the exception to
ServletExceptionError.jsp.
I refreshed the test.jsp many many times but tomcat never dispatch the exception
to SQLWarningError.jsp or SQLExceptionError.jsp.
I test them in weblogic6.1 and get the different result:
When the random is 0 ,weblogic dispatch the exception to
IOExceptionError.jsp.
When the random is 1 ,weblogic dispatch the exception to
SQLExceptionError.jsp.
When the random is 2 ,weblogic dispatch the exception to
SQLWarningError.jsp.
When the random is 3 and 4,weblogic dispatch the exception to
ServletExceptionError.jsp.
The weblogic's result fits the book says well but tomcat's does not.
Which one should I trust in the exam?
[ February 27, 2003: Message edited by: sun mellon ]

SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5
Calina Cazangiu
Ranch Hand

Joined: Feb 27, 2003
Posts: 30
Just curious - how does weblogic handle the exceptions coming from servlets vs exceptions coming from Jsp pages, same as tomcat?
Thx,
Calina
Calina Cazangiu
Ranch Hand

Joined: Feb 27, 2003
Posts: 30
And btw, we need to stick with the specs for the exam, not particular implementations of jsp containers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Same exception different handle in tomcat4.1 and weblogic6.1