J
jonesy
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
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>");
}
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
10.4.5 404 Not FoundFrom RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
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>");
}