Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2509985
  • 博文数量: 709
  • 博客积分: 12251
  • 博客等级: 上将
  • 技术积分: 7905
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-17 00:00
个人简介

实现有价值的IT服务

文章存档

2012年(7)

2011年(147)

2009年(3)

2008年(5)

2007年(74)

2006年(431)

2005年(42)

分类: Java

2006-08-12 23:25:23

===========================

Static.java

==================

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class StaticCount extends HttpServlet{
 static int classCount = 0 ;
 int count = 0 ;
 static Hashtable instances = new Hashtable() ;

 public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
  res.setContentType("text/html") ;
  PrintWriter out = res.getWriter() ;
  
  count ++ ;
  out.println("Since loading,this servlet has been accessed " + count + " times.") ;
  instances.put(this,this) ;
  out.println("There are currently "+ instances.size() + " instances.") ;

  classCount ++ ;
  out.println("Across all instances,this servlet class has been " + "accessed " + classCount + " times.");
 }

 public String getServletInfo(){
  return "A servlet that knows the name of the person to whom it;s" + "saying hello" ;
 }
}

===========================
 
阅读(3337) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~