DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42315>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42315

           Summary: Error Handling Custom Error Pages
           Product: Tomcat 5
           Version: 5.5.23
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Consider the following content as part of the server.xml

-------------------------------------------------
<Host name="www.example.com" appBase="C:/Example/Webapp" unpackWARs="false" 
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
        <Context path="/"  docBase="." reloadable="false" privileged="false">
                <Manager 
className="org.apache.catalina.session.StandardManager" 
pathname="C:/Example/Webapp/WEB-INF/httpsessions.ser"/>
        </Context>
</Host>
-------------------------------------------------

In order to make that host available in a local machine, you should 
add "example.com" to your hosts file (in windows, it's located at 
C:\WINDOWS\system32\drivers\etc\hosts)

Consider the following web.xml for the context defined above:

-------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>
<web-app>

        <servlet>
                <servlet-name>Controller</servlet-name>
                <servlet-class>com.example.Controller</servlet-class>
                <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
                <servlet-name>Controller</servlet-name>
                <url-pattern>/</url-pattern>
        </servlet-mapping>

    <error-page>
        <error-code>500</error-code>
        <location>/errors/500.htm</location>
    </error-page>
    
</web-app>
-------------------------------------------------

As you can see, a request made to http://www.example.com will be served by 
the "Controller" servlet, as its "url-pattern" property is set to "/". If I 
point my browser to http://www.example.com/errors/500.htm Tomcat serves me the 
right static html file.
However, when a ServletException occurs (error 500), instead of showing the 
static error page defined in the previous web.xml, I get the default Error 500 
Tomcat page, and the Catalina.out file shows this:

-------------------------------------------------
SEVERE: Exception Processing ErrorPage[errorCode=500, location=/errors/500.htm]
-------------------------------------------------

In order to reproduce this bug, consider the following servlet as the 
Controller.java :

-------------------------------------------------
package com.example;

import javax.servlet.*;
import javax.servlet.http.*;

public class Controller extends HttpServlet{

        public void init(ServletConfig conf) throws ServletException{
                super.init(conf);
        }

        public void destroy(){
        }

        public void doGet(HttpServletRequest req,HttpServletResponse res) 
throws ServletException{
                doPost(req,res);
        }

        public void doPost(HttpServletRequest req,HttpServletResponse res) 
throws ServletException{
                throw new ServletException("Force Error 500");
        }
}
-------------------------------------------------

I think this is strange bug, as calling the full 
http://www.example.com/errors/500.htm gives me the page it should be shown 
when an error 500 occurs, which means Tomcat can access perfectly to that 
file, but at the time of showing that page as a result of an exception, then 
it can't access to that location.

In order to resolve that issue, I've added the following content to my web.xml 
file as temporary fix to this issue:

-------------------------------------------------
<servlet>
        <servlet-name>Error500</servlet-name>
        <servlet-class>com.example.Error500</servlet-class>
        <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
        <servlet-name>Error500</servlet-name>
        <url-pattern>/errors/*</url-pattern>
</servlet-mapping>
-------------------------------------------------

This would be the content of the Error500 servlet:

-------------------------------------------------
package com.example;

import javax.servlet.*;
import javax.servlet.http.*;

public class Error500 extends HttpServlet{

        public void init(ServletConfig conf) throws ServletException{
                super.init(conf);
        }

        public void destroy(){
        }

        public void doGet(HttpServletRequest req,HttpServletResponse res) 
throws ServletException{
                doPost(req,res);
        }

        public void doPost(HttpServletRequest req,HttpServletResponse res) 
throws ServletException{
                try{
                        res.sendRedirect("/errors/500.htm");
                }
                catch(Exception ignored){}
        }
}
-------------------------------------------------

I've tested this on 5.5.23 and 5.5.20.

Thanks!

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to