Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running an Apache Tomcat server with 2 custom servlets. The tree structure looks like:

$CATALINA_HOME/webapps/
         ROOT/
           WEB-INF/
         servlet1/
           META-INF/
           WEB-INF/
         servlet2/
           META-INF/
           WEB-INF/

I am trying to add a custom error html page for each servlet that will be displayed on error 400, 404 and when there is an exception on the servlet (such as the information that was supposed to be sent to the servlet on the http request is not there)

I added to $CATALINA_HOME/webapps/servlet1/WEB-INF/web.xml

 <error-page>
   <error-code>400</error-code>
   <location>/error.html</location>
 </error-page>
 <error-page>
   <error-code>404</error-code>
   <location>/error.html</location>
 </error-page>
 <error-page>
   <exception-type>java.lang.Throwable</exception-type>
   <location>/error.html</location>
 </error-page>

and I created error.html in $CATALINA_HOME/webapps/ROOT/. This doesn't seem to be working. When I type" www.server.com/servlet1/SomRandomStuff to get a 404, a blank page is displayed, not error.html. Something else happens when I call the servlet without passing the correct info to it, the browser will ask me if i want to download a file.
I've tried placing error.html not on ROOT but on the servlet1 directory. Didn't work. I checked that error.html has the correct permissions, it is OK. I am out of ideas and the few tutorials I found online are very vague.

What am I doing wrong? How do I achieve this - display a custom error page per servlet?

Thank you for the help.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You have your page paths starting with slashes:

 <error-page>
   <error-code>400</error-code>
   <location>**/error.html**</location>
 </error-page>
 <error-page>
   <error-code>404</error-code>
   <location>**/error.html**</location>
 </error-page>
 <error-page>
   <exception-type>java.lang.Throwable</exception-type>
   <location>**/error.html**</location>
 </error-page>

In this case it might be looking for them in the root of the drive.

If they are in the same folder as web.xml you can try it this way ./error.html

Other than that, I would recommend trying the full path to the file: /var/www/error/error.html or whatever your situation is.

share|improve this answer
    
Eli, thank you. It is still showing the same behavior, even when I put the full path to error.html –  Mr Aleph Mar 31 '11 at 13:21
    
Ok. I managed to make it work for standard html errors (400, 404, etc). I just needed to place the error.html in the correct location. Now for the servlet being called without arguments: it still offers me to download it. Any ideas? –  Mr Aleph Mar 31 '11 at 14:02
    
Check your directory settings, it is skipping my mind right now, but there is essentially a directive command which has to be changed in order to "open in browser" not "download" files –  Eli Mar 31 '11 at 14:05
    
Thanks again but I am working blind right now since I have no idea where to even begin looking –  Mr Aleph Mar 31 '11 at 14:34
    
I'm trying a few things, but here is a good beginner tutorial on servlets that may possibly help get you headed in the right direction: cs.calstatela.edu/~abbott/Courses/CS_320b/… –  Eli Mar 31 '11 at 14:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.