实现有价值的IT服务
全部博文(709)
分类: 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" ;
}
}