• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Servlet Error Page

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

As a result of this wonderful Head First JSP & Servlets book, I can configure error.jsp pages for my application and for individual jsp's. However, I would like to know if there's a way to configure an error jsp page for a servlet as well.

I have a servlet gets info from a db and forwards to a jsp for the view. But sometimes the code in the servlet throws an exception, and I want to direct users to a specific error page rather than an application catch-all. How should I do that?

Thanks!

Tom
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Declare a general error page or pages (you can declare different pages for different types of errors) in the web.xml file. This will handle all errors not otherwise handled so that you do not need to declare anything for each indovidual JSP or servlet.
 
Tom McAmmond
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah... but I *want* to have a special error page for a couple of my servlets. Say I have 100 servlets, but 5 of them need an error page that's different than the pages for the other 95 servlets. Can I do that?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your servlets, you can catch an exception and forward to any page you like.
 
reply
    Bookmark Topic Watch Topic
  • New Topic