Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111346
  • 博文数量: 48
  • 博客积分: 2210
  • 博客等级: 大尉
  • 技术积分: 540
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-16 17:59
文章分类

全部博文(48)

文章存档

2010年(1)

2009年(15)

2008年(32)

我的朋友

分类: Java

2008-03-26 12:00:14

//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) |
给主人留下些什么吧!~~