Tomcat安装在D:\Tomcat55
1:在D:\Tomcat55\webapps\ROOT\WEB-INF目录下创建classes目录
2:编写servlet类(放在上面的classes目录下)
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("
Hello World!");
out.println("");
out.println("");
out.println("Hello World!
");
out.println("
");
out.println("");
}
}
3:把servlet库添加到环境变量
set CLASSPATH=D:\Tomcat55\common\lib\servlet-api.jar;%CLASSPATH%
4:编译servlet类
javac HelloWorld.java
5:修改web.xml文件,增加以下内容
HelloWorld
HelloWorld
HelloWorld
/HelloWorld
6:重启tomcat
7:浏览器输入就能看到输出
阅读(883) | 评论(0) | 转发(0) |