Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Changing default error message

Thread view: 
jonesy <3 - 20 Oct 2006 03:26 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
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.