一个简单的servlet
我第一次接触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://localhost:8080/chap06/servlet/Test试试
------解决方案--------------------环境变量CLASSPATH中的加d:\Tomcat 5.0\common\lib\servlet-api.jar
------解决方案--------------------输出的错误是什么?
------解决方案--------------------http://localhost:8080/Test
------解决方案--------------------楼主你的项目放在C:\tomcat5.5\webapps\ 的名字是甚么?如果是test的话
由你的web.xml
<servlet-mapping>
<servlet-name> Test </servlet-name>
<url-pattern> /Test </url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->