I am learning how to set to set
servlet name in the location of
<error-page> in web.xml, I do not why I get page 'Page Can not displayed ' when I invoked
http://localhost:8080/myWeb/practicse/error2 Here's my snippet
========== ErrorTest2.java
public void doGet( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
System.out.println("In ErrorTest2 class, throw ServletException exception.");
throw new IOException("wrong match");
}
========== MyErrorServlet2.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
String msg = (String) req.getAttribute ("javax.servlet.error.message");
System.out.println(" my error message is: " + msg );
PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println("<html><body>");
out.println("<br>Ha, error message is: " + msg );
out.println("</body></html>");
}
========== web.xml ================
<servlet>
<servlet-name>ET202</servlet-name>
<servlet-class>coreservlets.ErrorTest2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ET202</servlet-name>
<url-pattern>/practicse/error2</url-pattern>
</servlet-mapping>
<error-page>
<exception-type>java.io.IOException</exception-type>
<location>/servlet/MyErrorServlet2</location> <!-- correct?? -->
</error-page>
<servlet>
<servlet-name>MyErrorServlet2</servlet-name><!-- correct ?? -->
<servlet-class>coreservlets.MyErrorServlet2</servlet-class>
</servlet>
=============
Anybody can help?
Thanks in advance!