I am making website using java http servlets, and I would like to
customise the error message that users see when they try to access a
file that no longer exists.
This is the error message that is currently displayed:
Error 404--Not Found
>From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No
indication is given of whether the condition is temporary or permanent.
If the server does not wish to make this information available to the
client, the status code 403 (Forbidden) can be used instead. The 410
(Gone) status code SHOULD be used if the server knows, through some
internally configurable mechanism, that an old resource is permanently
unavailable and has no forwarding address.
Below is code from my servlet that I tried:
try
{
res.sendRedirect("/Leave.xls"); //this redirects the user to the
file that sometimes might not exist
}
catch (FileNotFoundException e) //this is my attempt at creating a
custom error message
{
out.println("<HTML>\n<HEAD>\n<TITLE>Access Denied</TITLE>\n");
out.println("<link rel='stylesheet' type='text/css'
href='/style.css' media='screen' />\n");
out.println("</HEAD>");
out.println("<br><p>The file you requested does not currently
exist. Please try again later.</p>");
out.println("<p>If this error occurs again, please <a
href='/servlets/Contact'>contact us</a>.</p>");
out.println("<p>Otherwise, Return to the <a
href='/servlets/Home'>home page</a>");
out.println("</font>\n</BODY>\n</HTML>");
}
hiwa - 20 Oct 2006 04:27 GMT
> I am making website using java http servlets, and I would like to
> customise the error message that users see when they try to access a
[quoted text clipped - 36 lines]
> out.println("</font>\n</BODY>\n</HTML>");
> }
Use <error-page> element of your web.xml file.
Simon Brooke - 20 Oct 2006 09:28 GMT
> I am making website using java http servlets, and I would like to
> customise the error message that users see when they try to access a
[quoted text clipped - 22 lines]
> }
> catch (FileNotFoundException e) //this is my attempt at creating a
It redirects the user, but it doesn't go and find the file itself, so the
exception will never be thrown.
Include at the end of your web.xml file, the following:
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>

Signature
simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
Ring of great evil
Small one casts it into flame
Bringing rise of Men ;; gonzoron
jonesy <3 - 23 Oct 2006 06:46 GMT
thanks!
> > I am making website using java http servlets, and I would like to
> > customise the error message that users see when they try to access a
[quoted text clipped - 38 lines]
> Small one casts it into flame
> Bringing rise of Men ;; gonzoron