| Author |
avoiding the 404 error page
|
james evangelisti
Greenhorn
Joined: Sep 11, 2004
Posts: 6
|
|
Hi all! I'm writing an application using servlet-JSP and I've got a little problem. My menu has a reference to the help pages (simple html format) in which I explain instructions about the current function selected. I store these html files in a separated directory on the server. I've not written all the help pages and for now I would want to redirect the user to a defalt page ("NO DOCUMENTATION AVAILABLE") instead of returning the 404 error page, if the corrisponding help page is not found on the server. I thought I had to check the status code of the response before committing but it seems not possible. Does anyone have suggestions?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
|
You can declare an alternate page of your own construction to be dislayed in the event of a 404 error within your web.xml file.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Julian Kennedy
Ranch Hand
Joined: Aug 02, 2004
Posts: 823
|
|
Hello James, Welcome to JavaRanch! Search this forum for "error-page". Jules
|
 |
james evangelisti
Greenhorn
Joined: Sep 11, 2004
Posts: 6
|
|
OK, thanks. It seems I should include the following code in the deployment descriptor file: <error-page> <error-code>404</error-code> <location>/ErrorPage.jsp</location> </error-page> But it still seems weird to me that I cannot handle this event through simple code.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
But it still seems weird to me that I cannot handle this event through simple code.
How? Where would you put such code? When the server cannot locate the resource that the URL is pointing to, how would it know what code of yours to call unless you tell it (with the error declaration)?
|
 |
Kitty Dayal
Ranch Hand
Joined: Jul 22, 2004
Posts: 89
|
|
Hey Bear, Can we tweek tomcat5.0 to do auto-reloading of pages. I started out working with tomcat5.0 and am having some trouble everytime restarting the server, or changing the web.xml file for new servlets. why can't tomcat just look at the /WEB-INF/classes and locate the class files by itself like orion does. With orion i don't have to reload/restart, it plain simple. Thanks, Kits
|
 |
james evangelisti
Greenhorn
Joined: Sep 11, 2004
Posts: 6
|
|
I expected to find a getStatus() method in the HttpServletResponse interface in order to check the status code before committing the response. But maybe this is stupid, I'm not that J2EE expert yet!
|
 |
Julian Kennedy
Ranch Hand
Joined: Aug 02, 2004
Posts: 823
|
|
James, The problem is that a request for something that doesn't exist never finds its way to your servlet because, well ... it doesn't exist! The error-page declaration is a very neat solution to this problem; much neater than bespoke code that you'd potentially have to write in many places. Jules
|
 |
james evangelisti
Greenhorn
Joined: Sep 11, 2004
Posts: 6
|
|
ok, I got very helpful answers to my request. thanks to all you guys. James
|
 |
 |
|
|
subject: avoiding the 404 error page
|
|
|