You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Héctor Garcia Peris <he...@ivie.es> on 2002/01/11 13:19:31 UTC

Change the default error message

Hello all,

This is the first time I write to this page, and I send a salutation to all 
people.
Well, this is my question. I have installed jakarta tomcat 3.2.2 in a linux 
machine. All works fine but I want change one thing and I don't know how 
can I make it. When occurs some error in a servlet, the servlet engine 
sends a response like this:

Error: 500
Localizacion: /examples/servlet/EnbreveServlet
Error interno del servlet:

java.lang.NullPointerException
         at EnbreveServlet.doGet(EnbreveServlet.java:86)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at 
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
         at org.apache.tomcat.core.Handler.service(Handler.java:287)
         at 
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at 
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
         at 
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
         at 
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
         at 
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at 
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
         at java.lang.Thread.run(Thread.java:484)

Can I change this information to a default html page?

Thanks.

PS: Could be this is a FAQ, but I have searching in the FAQ-o-matic and in 
the archive list and I can't find answer to my question.


---------------------------------------------------------------------
Héctor Garcia Peris
Dpto. Informática
Instituto Valenciano de Investigaciones Económicas S.A. (Ivie)
C/ Guardia Civil, 22 esc-2 1º 46020 - Valencia (Spain)
Tfno.: +34 - 963190050 / +34 - 963930816
Fax.: +34 - 963190055 / +34 - 963930856
e-mail: hector.garcia@ivie.es
----------------------------------------------------------------------



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: Change the default error message

Posted by Héctor Garcia Peris <he...@ivie.es>.
At 08:08 11/01/02 -0600, you wrote:
>Oh the dangers of modifying code without first testing it!
>
>I modified that from a plain 'Exception', because I thought I was being
>clever. Catch either the exact specific Exceptions that may be thrown (eg:
>NullPointer, IO) or just catch 'Exception', as I was originally doing.

Well, I can catch Exception, but know it doesn't works the sendRedirect 
method that you has write. I put the following:

         protected void sendErrorRedirect(HttpServletRequest request, 
HttpServletResponse response, String errorPageURL, Throwable e) {
         try {
       //request.setAttribute ("javax.servlet.jsp.jspException", e);
                         getServletConfig().getServletContext().getRequestDispatcher(errorPageURL).forward(request, 
response);
         } catch (Exception ex) {
       log(getServletName() + ".sendErrorRedirect ", ex);
         }
         }

And in the catch part:

} catch (Exception ex) {
    sendErrorRedirect(req, resp, "http://hgarcia/error.html", ex);
}

How can I redirect an html page, not a jsp page?

Thanks.



---------------------------------------------------------------------
Héctor Garcia Peris
Dpto. Informática
Instituto Valenciano de Investigaciones Económicas S.A. (Ivie)
C/ Guardia Civil, 22 esc-2 1º 46020 - Valencia (Spain)
Tfno.: +34 - 963190050 / +34 - 963930816
Fax.: +34 - 963190055 / +34 - 963930856
e-mail: hector.garcia@ivie.es
----------------------------------------------------------------------



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: Change the default error message

Posted by Mike Curwen <mi...@qunara.com>.
Oh the dangers of modifying code without first testing it!

I modified that from a plain 'Exception', because I thought I was being
clever. Catch either the exact specific Exceptions that may be thrown (eg:
NullPointer, IO) or just catch 'Exception', as I was originally doing.

-----Original Message-----
From: Héctor Garcia Peris [mailto:hector.garcia@ivie.es]
Sent: Friday, January 11, 2002 7:25 AM
To: Tomcat Users List
Subject: RE: Change the default error message


At 07:16 11/01/02 -0600, you wrote:
>You could use a JSP error page from a servlet.
>
>Catch any ServletException errors, and do a redirect to your JSP error
page.
>
>Here's short snips from one of my servlets:
>try {
>   //sending email from the servlet...
>} catch (ServletException ex) {
>    log("Failure to send email", ex);
>    sendErrorRedirect(req, res, "/error.jsp", ex);
>}
>
>
>protected void sendErrorRedirect(HttpServletRequest request,
>HttpServletResponse response, String errorPageURL, Throwable e) {
>    try {
>       request.setAttribute ("javax.servlet.jsp.jspException", e);
>
>getServletConfig().getServletContext().getRequestDispatcher(errorPageURL).f
o
>rward(request, response);
>    } catch (Exception ex) {
>       log(getServletName() + ".sendErrorRedirect ", ex);
>    }
>}
>
>
>Hope that helps...


But, I can't catch ServletException. When I try to catch I get the
following message:

EnbreveServlet.java:102: exception javax.servlet.ServletException is never
thrown in body of corresponding try statement
         } catch (ServletException se ) {
           ^



---------------------------------------------------------------------
Héctor Garcia Peris
Dpto. Informática
Instituto Valenciano de Investigaciones Económicas S.A. (Ivie)
C/ Guardia Civil, 22 esc-2 1º 46020 - Valencia (Spain)
Tfno.: +34 - 963190050 / +34 - 963930816
Fax.: +34 - 963190055 / +34 - 963930856
e-mail: hector.garcia@ivie.es
----------------------------------------------------------------------



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: Change the default error message

Posted by Héctor Garcia Peris <he...@ivie.es>.
At 07:16 11/01/02 -0600, you wrote:
>You could use a JSP error page from a servlet.
>
>Catch any ServletException errors, and do a redirect to your JSP error page.
>
>Here's short snips from one of my servlets:
>try {
>   //sending email from the servlet...
>} catch (ServletException ex) {
>    log("Failure to send email", ex);
>    sendErrorRedirect(req, res, "/error.jsp", ex);
>}
>
>
>protected void sendErrorRedirect(HttpServletRequest request,
>HttpServletResponse response, String errorPageURL, Throwable e) {
>    try {
>       request.setAttribute ("javax.servlet.jsp.jspException", e);
>
>getServletConfig().getServletContext().getRequestDispatcher(errorPageURL).fo
>rward(request, response);
>    } catch (Exception ex) {
>       log(getServletName() + ".sendErrorRedirect ", ex);
>    }
>}
>
>
>Hope that helps...


But, I can't catch ServletException. When I try to catch I get the 
following message:

EnbreveServlet.java:102: exception javax.servlet.ServletException is never 
thrown in body of corresponding try statement
         } catch (ServletException se ) {
           ^



---------------------------------------------------------------------
Héctor Garcia Peris
Dpto. Informática
Instituto Valenciano de Investigaciones Económicas S.A. (Ivie)
C/ Guardia Civil, 22 esc-2 1º 46020 - Valencia (Spain)
Tfno.: +34 - 963190050 / +34 - 963930816
Fax.: +34 - 963190055 / +34 - 963930856
e-mail: hector.garcia@ivie.es
----------------------------------------------------------------------



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: Change the default error message

Posted by Mike Curwen <mi...@qunara.com>.
You could use a JSP error page from a servlet.

Catch any ServletException errors, and do a redirect to your JSP error page.

Here's short snips from one of my servlets:
try {
  //sending email from the servlet...
} catch (ServletException ex) {
   log("Failure to send email", ex);
   sendErrorRedirect(req, res, "/error.jsp", ex);
}


protected void sendErrorRedirect(HttpServletRequest request,
HttpServletResponse response, String errorPageURL, Throwable e) {
   try {
      request.setAttribute ("javax.servlet.jsp.jspException", e);

getServletConfig().getServletContext().getRequestDispatcher(errorPageURL).fo
rward(request, response);
   } catch (Exception ex) {
      log(getServletName() + ".sendErrorRedirect ", ex);
   }
}


Hope that helps...

-----Original Message-----
From: Héctor Garcia Peris [mailto:hector.garcia@ivie.es]
Sent: Friday, January 11, 2002 6:20 AM
To: tomcat-user@jakarta.apache.org
Subject: Change the default error message


Hello all,

This is the first time I write to this page, and I send a salutation to all
people.
Well, this is my question. I have installed jakarta tomcat 3.2.2 in a linux
machine. All works fine but I want change one thing and I don't know how
can I make it. When occurs some error in a servlet, the servlet engine
sends a response like this:

Error: 500
Localizacion: /examples/servlet/EnbreveServlet
Error interno del servlet:

java.lang.NullPointerException
         at EnbreveServlet.doGet(EnbreveServlet.java:86)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
         at org.apache.tomcat.core.Handler.service(Handler.java:287)
         at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
         at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
         at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:213)
         at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
         at java.lang.Thread.run(Thread.java:484)

Can I change this information to a default html page?

Thanks.

PS: Could be this is a FAQ, but I have searching in the FAQ-o-matic and in
the archive list and I can't find answer to my question.


---------------------------------------------------------------------
Héctor Garcia Peris
Dpto. Informática
Instituto Valenciano de Investigaciones Económicas S.A. (Ivie)
C/ Guardia Civil, 22 esc-2 1º 46020 - Valencia (Spain)
Tfno.: +34 - 963190050 / +34 - 963930816
Fax.: +34 - 963190055 / +34 - 963930856
e-mail: hector.garcia@ivie.es
----------------------------------------------------------------------



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>