Tomcat 404 Custom Error

B

Bryce

I'm having a problem using a custom 404 error page with Tomcat. Here's
what I've done:

Got the following method in my servlet:

public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {

response.sendError(HttpServletResponse.SC_NOT_FOUND);
}

This will generate a 404 error.

My web.xml file has the following declared after my servlet
declaration:

<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>

I've got an html file 404.html located in the root of my
webapplication. So far so good.

In Mozilla, everything works as expected.

In IE... I get the generic "HTTP 404 Not Found" page.

Through some trial and error, and the wonders of Google, I discovered
that IE has an option "Show friendly HTTP Messages", which by default,
is checked. Unchecking this allows my custom 404 page to display
properly.

The problem is, I can't expect my customers to go in and make changes
to their IE configurations.

I'm thinking of using a Filter which will redirect to a custom page.
Any other ideas that sound better? Maybe I'm configuring Tomcat
incorrectly?

Thanks.
 
B

Bryce

Try using response.sendRedirect("http://blah/404.html"); that should do
the trick. It'll automatically redirect the browser to the 404 error
page.

Thanks. I thought of that. I was just hoping for a way to just specify
it in the web.xml like I can with apache...
 
A

Andrea Desole

Thanks. I thought of that. I was just hoping for a way to just specify
it in the web.xml like I can with apache...

look at error-page in the web.xml. There you also have an error-code tag.
 
B

Bryce

look at error-page in the web.xml. There you also have an error-code tag.

See my first message.

I do that, but IE decides it wants to use its own error page. It works
when I change IE's option "Show friendly HTTP error messages" off. I
was hoping there was another way around it other than redirecting in
the code.
 
A

Andrea Desole

Bryce said:
See my first message.
ops, sorry. It was actually pretty visible in your message, I don't know
why I didn't see it. Got to pay more attention next time.
I do that, but IE decides it wants to use its own error page. It works
when I change IE's option "Show friendly HTTP error messages" off. I
was hoping there was another way around it other than redirecting in
the code.
I don't think it's a problem with your configuration. How long is your page?

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q294807

<quote>
these "friendly" error messages are only displayed if the response that
is sent to the client is less than a specified threshold. For example,
to see the exact text of an HTTP 500 response, the content length must
be greater than or equal to 512 bytes
</quote>
 
B

Bryce

I don't think it's a problem with your configuration. How long is your page?

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q294807

<quote>
these "friendly" error messages are only displayed if the response that
is sent to the client is less than a specified threshold. For example,
to see the exact text of an HTTP 500 response, the content length must
be greater than or equal to 512 bytes
</quote>

Ahhh... That was it. Brilliant. You know, I saw that article, but I
skimmed over it and just assumed it was talking about solutions for
IIS.

Thanks.
 

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,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top