您的位置:首页 > 移动开发 > 微信开发

小程序之统计网页访问人数

2017-01-05 16:32 211 查看
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);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java 统计访问