File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Problem with Custom Error Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with Custom Error Page" Watch "Problem with Custom Error Page" New topic
Author

Problem with Custom Error Page

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I am having a problem with a custom error page. I have the following information in my web.xml file:



Here is FileNotFound.java



And then my JSP



And all I get is the default HTTP 404 File Not Found page. I don't get my custom page. I don't even get Tomcat's default error page unless I remove the custom error from the web.xml file.

I have also tried specifying the JSP instead of mapping through a servlet but that gets me the same bad results. Any tips?

Thanks.


GenRocket - Experts at Building Test Data
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
How about adding a printout to your processRequest to check if you get there?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, it is getting to the servlet. If I explicity call that error page using my servlet mapping

http://localhost:8080/anykey/filenotfound

I see the error page just fine. But if I call some arbitrary page that doesn't exist, I get the default HTTP 404 Page Not Found that most HTTP Servers tend to throw. Not even the Tomcat specific 404.
[ July 30, 2004: Message edited by: Gregg Bolinger ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I just did a test here at home with a fresh test project that only has an index page and an error page and everything works fine. So I guess I am going to have to see what is different when I get back to work.

This is so strange though because I did everything exactly the same...
Bruno Marti
Greenhorn

Joined: Jul 30, 2004
Posts: 2
I had the same problem yesterday with my web.xml definition
<error-page>
<error-code>404</error-code>
<location>/common/jsp/errorPage.jsp?ID=404</location>
</error-page>
I always received the default 404-page of the browser.

Solution:
there is a minimum limit of the errorpage size.
Add some more text to your errorpage and it'll work (hope so)

have a look at:
http://www.404-error-page.com/404-error-page-too-short-problem-microsoft-ie.shtml
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
(After only a quick read...)

Are you testing with IE? Only IE? Is IE configured to display "friendly" error pages?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Bruno Marti:
I had the same problem yesterday with my web.xml definition
<error-page>
<error-code>404</error-code>
<location>/common/jsp/errorPage.jsp?ID=404</location>
</error-page>
I always received the default 404-page of the browser.

Solution:
there is a minimum limit of the errorpage size.
Add some more text to your errorpage and it'll work (hope so)

have a look at:
http://www.404-error-page.com/404-error-page-too-short-problem-microsoft-ie.shtml


That is the most retarted thing I have ever witnessed. But all is well now that I made my error page longer. :roll:

Thanks a bunch.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

So here is something else interesting that is happening. Now, not matter what page I visit in my web app, my FileNotFound class is being ran. The app functions as normal, except I have a System.out.print in the FileNotFound servlet and it is printing my out statement about 3 times per page. Is this normal?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, after some better debugging...I have some images that I have not fixed the url on to display and appearntly for ANY resource that the server can't find you get a 404. So it was calling my error page for those images not being available. I didn't realize it did this.
Arthur Doler
Greenhorn

Joined: Aug 13, 2004
Posts: 1
I spent a day and a half trying to figure out what the heck was going on until I stumbled on your solution.

That's quite possibly the single stupidest policy on error pages I can think of.

Thanks a bunch for the clue-in!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Custom Error Page