| 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.
|
 |
 |
|
|
subject: Same exception different handle in tomcat4.1 and weblogic6.1
|
|
|