手動編寫一個servlet部署在tomcat上
阿新 • • 發佈:2019-01-30
先編寫一個簡單的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都要注意