how-to show a servlet exception in a jsp error-page?
843841Jun 25 2003 — edited Jun 27 2003Hello,
I have the following problem:
After a servlet exception was thrown, I want to "link" to a JSP
error page (without using a try-catch block!) to process (rootCause, Message, etc.)
the exception. My web.xml seems not to work for me (see below).
Exist there a programmable way?
//- - - - - - - - - - - - CUT HERE - - - - - - - - - - - -
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>testservlet.Test</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>*.init</url-pattern>
</servlet-mapping>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error.jsp</location>
</error-page>
</web-app>
//- - - - - - - - - - - - CUT HERE - - - - - - - - - - - -
I tried to use the <error-code>500 instead of <error-page> as well,
but does still not work.
My configuration is: eclipse IDE, J2SDK1.4.2_02 and Tomcat4.1.24.
I wrote a small servlet to simulate the servlet-exception (see below)
Thanks for your help!
Regards,
Frank.
//- - - - - - - - - - - - CUT HERE - - - - - - - - - - - -
/*
* Created on 25.06.2003
*/
package testservlet;
import java.io.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.*;
import javax.servlet.ServletException;
public class Test extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet( request, response );
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//servlet exception goes here
String test = null;
System.out.println(test.toString());
//just for testing-purpose
out.println("<html>");
out.println("<head>");
out.println("<title>No Exception was thrown...</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\"><b>No Exception was thrown.</b> ");
out.println("</body>");
out.println("</html>");
}
}
//- - - - - - - - - - - - CUT HERE - - - - - - - - - - - -