我第一次接触servlet,完全按书上的做,不知道怎么不能运行,特此请教
TestServlet.java文件
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out=response.getWriter();
out.println("<html><body><h1>welcome to java world</h1></body></html>");
out.flush();
}
}
TestServlet.java文件编译成的TestServlet.class放在C:\tomcat5.5\webapps\ROOT\chap06\WEB-INF\classes\test目录下
还有web.xml文件
<?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>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>Test</servlet-name>
<display-name>Test</display-name>
<description>A test Servlet</description>
<servlet-class>test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
</web-app>
web.xml文件放在C:\tomcat5.5\webapps\ROOT\chap06\WEB-INF
在浏览器里输入http://localhost:8080/chap06/Test
,错误是这样的
HTTP Status 404 - /chap06/Test
--------------------------------------------------------------------------------
type Status report
message /chap06/Test
description The requested resource (/chap06/Test) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.20
我也写了差不多的小例子,都是这样,真郁闷都搞了n多次拉还是这样。我的配置是tomcat5.5。tomcat下的examples里的例子都可以运行的。我自己的就不可以拉。请大侠帮忙啊