tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kirby Vandivort <kvand...@ks.uiuc.edu>
Subject Re: tomcat sending 200 response code instead of 404 when error-page used
Date Mon, 07 Jan 2002 05:55:39 GMT
Thanks for the response, but let me be a bit more specific in my
question.  I am using tomcat 4.0.1 standalone, so apache is not
involved.

Tomcat utilizes the <error-page> directive when it DOES realize that
there has been a problem in the code, and the error-page directive has
an error-type parameter that tells it the exact type of error that it
needs to utilize that particular error-page for.  (something like:
<error-page>  
  <error-type>404</error-type>
  <location>/404.html</location> 
</error-page>    )

So, I have set up an error-page directive in my web.xml file to tell
tomcat that it needs to do something special for 404s.  Tomcat is then
sending a response code of 200 and the 404.html file, rather than a
response code of 404 and the html file.

For my particular case it happens to be important what the response
code is, because it isn't a browser that is requesting the file.  It is
a program that does something special if it gets a 404 as opposed to a
200.  So, it needs to be a 404.  (for those that are curious, the
'program' is a JVM; when running an applet it will try to request class
files from the server; if it gets a 404 it knows that it can't find the
class.  If it gets a 200, it thinks that the html file is the binary of
the class file and gets really confused.)

Hope this helps make it more clear.


On Sun, Jan 06, 2002 at 07:31:34PM +0100, Nikola Milutinovic wrote:
> Kirby Vandivort wrote:
> 
> >Hello,
> >
> >I am using the <error-page> directive in my web.xml file to redirect
> >users to an html file, /404.html.
> >
> >When I do this, though, it appears that tomcat is sending a response
> >code of 200 instead of 404.  Is this the way that it should be?  It
> >seems to me it should send a response code of 404 and then go ahead and
> >send the contents of the 404.html file.
> >
> >Someone out there with a more recent knowledge of how http response
> >headers are parsed can possibly set me straight on this one.
> 
> I think Apache is doing just what it's told - it is displaying a web page. 
> There are several responses:
> 
> 2xx - OK
> 3xx - Redirect (moved to a different location)
> 4xx - Client request error
> 5xx - Server error
> 
> So, at the error page, Tomcat has no way of knowing which type of error you 
> wish to report and it is using the most common - "200 OK". After all, is it 
> really important to the web browser what the code was, when it gets a nice 
> custom error page?
> 
> I know, there might be caching issues involved. Mostly with IE, I might add. 
> And I might also add, if IE sees a 404 it might decide to jump in with IT'S 
> OWN friendly error page, which totally opscures the real error page.
> 
> Anyway, you can always directly manipulate response object *in a JSP page 
> and Servlet* Maybe there is some setting in web.xml, but I'm not sure.
> 
> Nix.
> 
> 
> --
> To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
> Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>

-- 

Kirby Vandivort                      Theoretical Biophysics Group
Email: kvandivo@ks.uiuc.edu          3051 Beckman Institute
http://www.ks.uiuc.edu/~kvandivo/    University of Illinois
Phone: (217) 244-5711                405 N. Mathews Ave
Fax  : (217) 244-6078                Urbana, IL  61801, USA

--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message