aspose file tools*
The moose likes Servlets and the fly likes Servlet Error Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Error Page" Watch "Servlet Error Page" New topic
Author

Servlet Error Page

Tom McAmmond
Ranch Hand

Joined: Feb 16, 2004
Posts: 58
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tom McAmmond
Ranch Hand

Joined: Feb 16, 2004
Posts: 58
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?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

In your servlets, you can catch an exception and forward to any page you like.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Error Page
 
Similar Threads
IS there a way to configure error page for android application?
web apps security
How to handle an Exception thrown in a Scriptlet in a .Tag File
controlling maxActiveSessions
Configuring a jsp page in web.xml