Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

web.xml error-page problem

 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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 ]
 
Ken Robinson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64985
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you are running the servlet container stand-alone and not fronted by apache?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct.
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also met this problem, I am running tomcat 5.0 standalone.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic