Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   How do I set the HTTP status of my error page to 404 in Tomcat? (http://www.velocityreviews.com/forums/t131013-how-do-i-set-the-http-status-of-my-error-page-to-404-in-tomcat.html)

Steven Hines 02-04-2004 02:11 PM

How do I set the HTTP status of my error page to 404 in Tomcat?
 
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" %>

John C. Bollinger 02-04-2004 03:39 PM

Re: How do I set the HTTP status of my error page to 404 in Tomcat?
 
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
jobollin@indiana.edu


Steven Hines 02-05-2004 10:12 AM

Re: How do I set the HTTP status of my error page to 404 in Tomcat?
 
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


All times are GMT. The time now is 10:09 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.