DemoServlet.java代码部分。
import java.io.*;
import javax.servlet.*;
public class DemoServlet implements Servlet{
ServletConfig config=null;
public void init(ServletConfig config){
this.config=config;
System.out.println("初始化完成");
}
public void service(ServletRequest req,ServletResponse res)
throws IOException,ServletException{
res.setContentType("text/html");
PrintWriter pwriter=res.getWriter();
pwriter.print("");
pwriter.print("
");pwriter.print("
Servlet示例程序
");pwriter.print("");
pwriter.print("");
}
public void destroy(){
System.out.println("servlet生命周期完成");
}
public ServletConfig getServletConfig(){
return config;
}
public String getServletInfo(){
return "由某人编写的演示程序";
}
}