> I have some problems to make custome error pages working. I have done my test with
>TC40-b7
> on Linux Redhat 7.1 Kernel 2.4.2.
1) The servlet ErrorHandlingServlet.java is in
$CATALINA_HOME/webapps/test/WEB-INF/classes:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
public class ErrorHandlingServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String param = req.getParameter("code");
if(param.equals("Servlet"))
throw new ServletException("ServletException thrown!!!");
else if(param.equals("Unavailable"))
throw new UnavailableException("UnavailableException");
else
res.sendError(404, "404 is returned");
}
}
2) The custom error pages are in $CATALINA_HOME/webapps/test/jsp/errorpage, an example
is
errorpage.jsp:
<%@ page isErrorPage="true" %>
<html>
<body bgcolor="red">
<h1> The exception msg is <%= exception.getMessage() %> </h1>
</body>
</html>
3) The Deployment descriptor $CATALINA_HOME/webapps/test/WEB-INF/web.xml is configured
as
follow:
<servlet>
<servlet-name>errorHandling</servlet-name>
<servlet-class>ErrorHandlingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>errorHandling</servlet-name>
<url-pattern>/eHandling</url-pattern>
</servlet-mapping>
...
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/jsp/errorpage/errorpage.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/jsp/errorpage/errorpageUn.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/jsp/errorpage/errorpage404.jsp</location>
</error-page>
When I accessed the ErrorHandlingServlet with the URL:
http://localhost:8080/test/servlet/ErrorHandlingServlet?code=Servlet, I expected the
TC to
return the custom error page /jsp/errorpage/errorpage.jsp. But it was the following
page
returned:
A Servlet Exception Has Occurred
javax.servlet.ServletException: ServletException thrown!!!
at ErrorHandlingServlet.doGet(ErrorHandlingServlet.java:13)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
...
It is interesting to note that when I put the error-page tags just bellow the taglib
tag, as
specified by the DTD, there was the following error message in the localhost_log.txt
when TC
was startedup:
2001-08-23 19:48:47 ContextConfig[/test] Parse error in application web.xml
org.xml.sax.SAXParseException: Element "web-app" does not allow "error-page" here.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3013)
at
org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(ValidatingParser.java:349)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1303)
...
So I have had to put error-page tags before the taglib tag, but the custom error page
could
still not be shown. Have I missed somethings?
Regards
Peiqiang Han