Tomcat not returning 404 for custom error page

Discussion in 'Java' started by Aleksi Kallio, Aug 4, 2003.

  1. I have configured my own error page for the 404 HTTP error like this:

    <error-page>
    <error-code>404</error-code>
    <location>/my404.jsp</location>
    </error-page>

    Tomcat responds to 404-causing requests by first sending a 302 (the page
    has moved) response, which redirects the browser to /my404.jsp - and it
    is served normally, with HTTP code 200 (OK). The problem is that link
    validator script can't catch missing pages, as no 404 is returned to
    client.

    How to fix this?
    Aleksi Kallio, Aug 4, 2003
    #1
    1. Advertising

  2. Aleksi Kallio wrote:
    > I have configured my own error page for the 404 HTTP error like this:
    >
    > <error-page>
    > <error-code>404</error-code>
    > <location>/my404.jsp</location>
    > </error-page>
    >
    > Tomcat responds to 404-causing requests by first sending a 302 (the page
    > has moved) response, which redirects the browser to /my404.jsp - and it
    > is served normally, with HTTP code 200 (OK). The problem is that link
    > validator script can't catch missing pages, as no 404 is returned to
    > client.
    >
    > How to fix this?
    >


    You could try leading off my404.jsp with

    <%
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    %>

    (Note that that clears the buffer, which is why it should come first, or
    at least early.)

    I wouldn't expect that to avoid the redirect, but it ought to cause the
    client to receive a 404 error in the end. Unless it sends Tomcat into
    an infinite loop... you'd better test.


    John Bollinger
    John C. Bollinger, Aug 4, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mupota Muchelemba
    Replies:
    1
    Views:
    899
    Tony Morris
    Feb 4, 2004
  2. Anders Skar
    Replies:
    1
    Views:
    2,086
    Anders Skar
    Jul 22, 2004
  3. Bryce

    Tomcat 404 Custom Error

    Bryce, Apr 13, 2005, in forum: Java
    Replies:
    6
    Views:
    38,791
    Bryce
    Apr 15, 2005
  4. Replies:
    3
    Views:
    974
    HalcyonWild
    Oct 14, 2005
  5. Sujan
    Replies:
    1
    Views:
    125
Loading...

Share This Page