//jpg格式代码 显示结果
package second;//chapter包
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class lifeCycleDemoServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
int count;
//Initialize global variables
public void init(ServletConfig config) throws ServletException {
super.init(config);
String initial=config.getInitParameter("initial");
try {
count=Integer.parseInt(initial);
} catch (Exception ex) {
count=0;
}
System.out.println("计算器Servlet已经成功初始化");
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("");
out.println("
lifeCycleDemoServlet");
out.println("");
count++;
out.println("自从加载后(读取初始化参数后,)");
out.println("这个Servlet已经被访问了");
out.println(count+"次");
out.println("
");
out.println("");
out.close();
System.out.println("该Servlet的doGet方法被执行了count+次");
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
阅读(1415) | 评论(0) | 转发(0) |