• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception handling

 
Bindesh Vij
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I trying to do exception handling of specific types and so i placed the following code in web.xml



I've two jsp files :
1)IOError.jsp
2) Welcome.jsp

The Welcome.jsp file looks like this..


But when i am starting up tomcat i'm not able to deploy it.. the console shows lots of exception of severe nature..


Is there something wrong with my web.xml file. Where can i get the schema specification for web.xml file...

I am sorry if i have posted in the wrong forum...Actually I don't know where to post this..

pls. help
 
Travis Berthelot
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find depending on the web.xml is a bad idea. Each container has its own way of dealing with things. Its easier to use the most simplistic approach. Which is the error="page.jsp" that is included in your jsps then redirect to the appropriate error page for a given exception. This give you the added benefit of seperation from all the servlet mappings. Its not a big deal until you start generating thousands of mappings.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find depending on the web.xml is a bad idea.


This is very bad advice, in my opinion. The web.xml file is intended as a stadardized way of specifying the behavior of web applications and should be depended upon. Any container that doesn't follow the specification is broken.

Relying on the error page declaration in JSPs is problematic. It assumes that your app is JSP-centric since it doesn't do a thing to help you handle exception processing in servlets (and JSP-centric apps are almost always a bad idea), and it has to specified in, and kept consistent in, each page.

You did not mention which version of Tomcat you are using, and what version of the Servlet spec you are coding to.
 
Bindesh Vij
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnx for replying

Yes i do agree with Bear, bcoz to me it appears that putting the code in web.xml gives you great flexibility of adding and removing specific listeners for particular error type without much chnage in the JSP.

Iam using Tomcat 5.1 with servlet spec 2.4
thnx
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this out.

- <web-app>
<display-name>ABC Application</display-name>
<description>ABC Application for XYZ stuff</description>
- <listener>
<listener-class>com.common.LogoutTracker</listener-class>
</listener>
- <servlet>
<servlet-name>AppController</servlet-name>
<servlet-class>com.servlet.AppAdminServlet</servlet-class>
</servlet>
- <servlet>
<servlet-name>FileUploader</servlet-name>
<servlet-class>com.servlet.UploadFileServlet</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>AppController</servlet-name>
<url-pattern>/AppController</url-pattern>
</servlet-mapping>
- <servlet-mapping>
<servlet-name>FileUploader</servlet-name>
<url-pattern>/FileUploader</url-pattern>
</servlet-mapping>
- <session-config>
<session-timeout>20</session-timeout>
</session-config>
- <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
- <error-page>
<error-code>404</error-code>
<location>/common/error.jsp</location>
</error-page>
- <error-page>
<exception-type>java.lang.IOException</exception-type>
<location>/common/ioExcep.jsp</location>
</error-page>
</web-app>
 
Bindesh Vij
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Adeel.

I've got it .I missed out a '/' in the location element. The modified element looks like this..




Thanks everybody...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!