Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How do I set the HTTP status of my error page to 404 in Tomcat?

Reply
Thread Tools

How do I set the HTTP status of my error page to 404 in Tomcat?

 
 
Steven Hines
Guest
Posts: n/a
 
      02-04-2004
Hi all - am having trouble finding an answer to this question.

I'm running Tomcat 4.1.27 on Windows 2000 Server, and I would like to
know how to manually set the HTTP status code of a web page to 404.
Allow me to explain...

I have recently rebuilt my old website but the search engines (in
particular YahooSeeker from inktomisearch.com) are still trying to
index pages under the old URLs they have stored in their databases. I
have a default user-friendly error page that is served whenever a use
encounters a 404. The trouble is that, when the search engines request
an old page, they get the error page. The logs tell me that this error
page is being served with an HTTP status of 200 which means the search
engines think that it's a valid page. This means that they continually
try to index old pages that aren't there anymore.

How can I manually set the HTTP status code of my error page to always
be 404, yet still show the user-friendly page to normal browsers?

All ideas gratefully received!

Thanks in advance,

Steve

PS can anyone tell me why I get so many & characters in web log
entries such as this:

yj1035.inktomisearch.com - - [04/Feb/2004:11:25:33 +0000] "GET
/scripts/display.cgi?type=hotels&city=238&&&&&&&&&&&&&first =1&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&sort=alpha
HTTP/1.0" 200 8678 "-" "YahooSeeker/1.0 (compatible; Mozilla 4.0; MSIE
5.5; http://help.yahoo.com/help/us/shop/merchant/)"


---------
TECH INFO
---------

Here are some of the relevant entries from my web.xml file:

<servlet>
<servlet-name>errorDispatcher</servlet-name>
<servlet-class>com.ora.jsp.servlets.ErrorDispatcherServlet</servlet-class>
<init-param>
<param-name>errorPage</param-name>
<param-value>/error.jsp?debug=log</param-value>
</init-param>
</servlet>

<!-- The mapping for the servlet to handle run-time errors -->
<servlet-mapping>
<servlet-name>errorDispatcher</servlet-name>
<url-pattern>/errorDispatcher</url-pattern>
</servlet-mapping>

<!-- Error pages -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/errorDispatcher</location>
</error-page>

<error-page>
<error-code>400</error-code>
<location>/errorDispatcher</location>
</error-page>

<error-page>
<error-code>401</error-code>
<location>/errorDispatcher</location>
</error-page>

<error-page>
<error-code>403</error-code>
<location>/errorDispatcher</location>
</error-page>

<error-page>
<error-code>404</error-code>
<location>/errorDispatcher</location>
</error-page>

<error-page>
<error-code>405</error-code>
<location>/errorDispatcher</location>
</error-page>

<error-page>
<error-code>408</error-code>
<location>/errorDispatcher</location>
</error-page>

<error-page>
<error-code>500</error-code>
<location>/errorDispatcher</location>
</error-page>


Also, my error page error.jsp contains the following:

<%@ page isErrorPage="true" %>
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      02-04-2004
Steven Hines wrote:

> How can I manually set the HTTP status code of my error page to always
> be 404, yet still show the user-friendly page to normal browsers?


You may be looking for HttpServletResponse.setStatus(int).


John Bollinger
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Steven Hines
Guest
Posts: n/a
 
      02-05-2004
Thanks for the suggestion John.

After posting my question, I did some more research and, (wouldn't you
know it?!) I found a thread that helped me out. the subject of the
thread is "Tomcat and custom error pages" and you can find it at

http://groups.google.com/groups?hl=e...3DN%26tab%3Dwg

My particular solution was to put the following line at the top of my
error page:

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

Cheers,

Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error HTTP 404 When I try to access a page with a Gridview lufrenette@reg6.health.nb.ca ASP .Net Web Services 1 12-06-2007 11:32 PM
http status 404 /login.jsp jitender Java 1 01-25-2005 02:05 PM
struts error: HTTP Status 404 - Servlet action is not available Geoff Winsor Java 6 01-13-2005 09:04 AM
How To Send Http/1.0 404 Not Found Error Page In C searcher1234 C Programming 1 10-31-2004 04:01 AM
HTTP error 404 when calling ASP page. Brian Rupert ASP General 4 02-09-2004 01:03 AM



Advertisments