我的servlet文件写的都没有问题,就是用网页访问的时候就提示“HTTP Status 404 - /wileyapp/servlet/chapter2.SimpleServlet”错误,请问是什么原因啊,我用的是tomcat服务器。
存放路径是:E:\apache-tomcat-6.0.13\webapps\wileyapp\WEB-INF\classes\chapter2\SimpleServlet.class
源代码如下:
package chapter2;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SimpleServlet extends HttpServlet {
public void init(ServletConfig config)
throws ServletException {
// Always pass the ServletConfig object to the super class
super.init(config);
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Simple Servlet</title></head>");
out.println("<body>");
// Outputs the address of the calling client
out.println("Your address is " + request.getRemoteAddr()
+ "\n");
out.println("</body></html>");
out.close();
}
}
存放路径是:E:\apache-tomcat-6.0.13\webapps\wileyapp\WEB-INF\classes\chapter2\SimpleServlet.class
源代码如下:
package chapter2;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SimpleServlet extends HttpServlet {
public void init(ServletConfig config)
throws ServletException {
// Always pass the ServletConfig object to the super class
super.init(config);
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Simple Servlet</title></head>");
out.println("<body>");
// Outputs the address of the calling client
out.println("Your address is " + request.getRemoteAddr()
+ "\n");
out.println("</body></html>");
out.close();
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>SimpleServlet</servlet-name>
<servlet-class>chapter2.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/SimpleServlet</url-pattern>
</servlet-mapping>
</web-app>
怎么还用wileyapp/servlet/chapter2.SimpleServlet作为访问路径,应该是/SimpleServlet