測試代碼
package servlet1;
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 servlet_test extends HttpServlet {
String message;
//構造函數
public servlet_test() {
super();
}
public void init() throws ServletException{
message = "this is message test";
}
//get方法請求
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(message);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
}
public void destroy(){
//nouthon
}
}
測試效果如圖: