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 web.xml error-page problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "web.xml error-page problem" Watch "web.xml error-page problem" New topic
Author

web.xml error-page problem

Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
(This is a web app configuration problem. Since we don't have a web apps forum, the Servlets forum seemed like a good place.)
If I'm lucky, I'm making a mistake.
I can't seem to get my custom 404 error page to show up in my web app, using both Tomcat 4.1.27 and Resin Server 3.0.6. Instead some generic error page likely created by the server is being displayed.
The following is my web.xml file. The error.jsp file is indeed located in the webapps/mywebapp directory.
Any ideas on what is wrong?
[ February 05, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
I am going to guess here, but I'm betting unless you have a piece of code that explicitly raises the 404 error, it may never reach the servlet container.
If a URL is requested that isn't there, the container probably looks at your web app and determines it's not a valid URL. I'm betting it doesn't even look at the web.xml settings and handles the 404 it's own way. If your code where to explicitly throw the 404, it would probably get picked up.
Again, this is a guess, but since most servers checked for this code before the Servlet Spec defined the <error-code> tag, they probably only use it when an HttpServletResponse sends the error.
Research if the server allows custom error pages at the server level, not the container. If putting a custom page there works, this is probably a problem that is not fixible without trial and error. If that's the case, experiment with a Servlet that you write that does nothing more than throw a 404. Make it's <servlet-mapping> element last and map it to *. If an explicit match is not found on any other <servlet-mapping> entries and a partial match is not found, it should forward to your servlet.
Again, just a guess. Hope it helps.
Kelvin Hung
Greenhorn

Joined: Jan 15, 2004
Posts: 29
As I know you don't need to explicitly raise 404. Can you access the error page directly? http://localhost/error.jsp?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Can you elaborate a bit on how you are testing this?
I used your web.xml as specified, gave it an index.jsp and an error.jsp, then asked for http://server:8080/app/hello.ugh and it correctly gave me the error page.
However, if the welcome page is missing, and you ask for http://server:8080/app/ it does not raise a 404, and never gives the error page.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I can access the error.jsp directly.
I'm testing it by trying to access a page that does not exist that would appear from the uri to be a page in the web app. Something like http://localhost:8080/mywebapp/nosuchpage.jsp
The welcome page seems to work fine.
Frank, which version of Tomcat worked for you?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

I assume you are running the servlet container stand-alone and not fronted by apache?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Correct.
danny liu
Ranch Hand

Joined: Jan 22, 2004
Posts: 185
I also met this problem, I am running tomcat 5.0 standalone.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Frank, which version of Tomcat worked for you?
Um, I didn't use Tomcat.
I originally used Resin 2.1 which I have running here all the time, then tried Resin 3.0.6 (as mentioned in your original post). If anything Resin 3.0.6 is slightly better at this - it catches the errors and shows the error page even if I give it
http://server:8080/app/
or
http://server:8080/app
If it's not an obvious suggestion, did you try clearing out Tomcat's JSP class cache and restarting?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
If it's not an obvious suggestion, did you try clearing out Tomcat's JSP class cache and restarting?
I did try that. I guess I'm just carrying around a curse.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
(Whistling...)
It seems to have been all Internet Explorer's fault.
Things work fine with Firebird and Mozilla.
For some reason Internet Explorer thinks it knows best and displays its own 404 page. This only seems to happen for me when running the app on the localhost.
Thanks all for your help.
[ February 07, 2004: Message edited by: Dirk Schreckmann ]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Dirk, did you set IE to not display it's own friendly error messages. That could be the problem.
Tool->Internet Options->Advanced
Make sure the "Show Friendly http error messages" is not checked.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: web.xml error-page problem