手动编写一个Servlet类需要以下几步:
(1)在D:\apache-tomcat-7.0.77\webapps\目录下新建一个WEB工程FirstProject,目录结构如下:
(2)在classes目录下放置Java源文件FirstProject:
package it.cn;
import java.io.*;
import javax.servlet.*;
public class FirstProject extends GenericServlet{
public void service(ServletRequest request, ServletResponse
response) throws ServletException, IOException{
OutputStream out = response.getOutputStream();
out.write("Hello Servlet!".getBytes());
}
}
(3)编译java源文件为.class文件:
需要配置环境变量classpath, 将环境变量CLASSPATH的值设置为:
.;C:\Tomcat 5.5\common\lib\servlet-api.jar
常见问题见博客:http://www.cnblogs.com/michaelkai/archive/2013/07/05/3173786.html