tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Wong <rw...@opsware.com>
Subject Re: Programmatically call the error page for a 500 error
Date Sat, 19 Feb 2005 17:07:10 GMT
Even if Tomcat 5 works this way, you are counting on a container 
specific implementation behavior that may be changed in future version.

Why not do it with a standard servlet approach?  You can specify an 
error handler in web.xml to handle different exception classes.

     <error-page>
         <exception-type>org.my.Exception1</exception-type>
         <location>/handler/case1.jsp</location>
     </error-page>
     <error-page>
         <exception-type>org.my.Exception2</exception-type>
         <location>/handler/case2.jsp</location>
     </error-page>
     <error-page>
         <exception-type>org.my.Exception3</exception-type>
         <location>/handler/case3.jsp</location>
     </error-page>

You application would raise the corresponding exception to trigger the 
handler page you want to display.  Or you can create a single custom 
exception with embedded information to a single error handler page that 
knows how to render different error report depending on the embedded 
information in the exception.  Note that inside the error page, you can 
get back the Exception object you raised.  So you have all the 
information you need to render the page properly.

That would guarantee to work in all Servlet 2.4 web containers.

Thanks,
--
Rick

Chris Hyzer wrote:

> Hello,
> 
> This works in Tomcat 4, but not 5 (5.0.25)
> 
> 
> response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
> 
> RequestDispatcher dispatcher =
> request.getRequestDispatcher(somePage);
> 
> dispatcher.forward(request, response);
> 
> 
> I would like to set a 500 error code, and call
> different pages in different circumstances.  Right now
> it calls the default Tomcat 500 page.  If I add an
> error page in the web.xml it will call that.  But I
> need to programmatically decide, so I can have a 500
> error go to various JSPs that communicate the problem.
> 
> Any ideas?
> Thanks,
> 
> Chris
> 
> ps. I tried an error page that was just text, so the
> error page is not triggering an error I believe... the
> same code works fine in tomcat 4 (.1.28 I think)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.8 - Release Date: 2/14/2005


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message