先编写一个简单的HelloWorld.java
package com.amarsoft.exercise;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
public class HelloWorld extends HttpServlet{
public void service(ServletRequest req, ServletResponse resp)
throws ServletException, IOException {
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>");
out.println("Java Servlet");
out.println("</title>");
out.println("</head>");
out.println("<body>");
out.println("helloworld");
out.println("</body>");
out.println("</html>");
}
}
我的apache在E:\JavaExercise\apache-tomcat-7.0.68下
在windows下的命令
能产生一个HelloWorld.class类
在web.xml中配置下servlet;
之后开启startup.bat运行结果
细节很多,cmd下javac后面-cp和-d都要注意