public class AServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//1 获得Application域中存放的统计数字
Integer count = (Integer) getServletContext().getAttribute("count");
//2 判断是否获得到统计数字
if(count == null){
//没获得到=> 将数字初始化为1
count = 1;
}else{
//获得到了=> 将数字加1
count += 1;
}
//3 输出,放回到Application域中
response.getWriter().write("you are the "+ count+" vistors");
getServletContext().setAttribute("count",count);
}
}