Forum Moderators: phranque

Message Too Old, No Replies

Tomcat how to respond with "410 Gone"

send custom, dynamic page with error code

         

sublime1

12:45 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Hi --

Using tomcat via Apache and...

I would like to send a useful page back to my users when they mistype a URL or go to a URL that is no longer in our system. But I want bots to know that the page is gone.

I have been sending 404's with a custom static page defined in the web.xml for Tomcat. But search engines don't seem to respond to 404s by removing content -- they keep trying and trying.

I could do the same thing with 410's I assume but what I really want is to send back a dynamic page (we can take a good guess at what they were looking for from the URL alone). Is there a way to send back a custom error page?

Thanks!

sublime1

7:01 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



In case anyone is interested, I sorted this out. No changes need to be made to web.xml; the <error-page> directives reference static files (although I suppose one could write a dynamic page to a file :-).

Really all you need to do is set the http status; and display the page as you would otherwise. This can be done using HttpServletResponse.setStatus() in Java. Browsers handle don't do anything special with a 410 -- they just display the page, which is exactly what I wanted.