Tomcat not returning 404 for custom error page

A

Aleksi Kallio

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?
 
J

John C. Bollinger

Aleksi said:
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
(e-mail address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top