UseServlet.java
ServletContext context = getServletContext();
Integer count = (Integer)context.getAttribute("counter");
if(count==null){
count=1;
context.setAttribute("counter", count);
}else {
context.setAttribute("counter", count+1);
}
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
PrintWriter out = resp.getWriter();
out.println("<!DOCTYPE>");
out.println("<html>");
out.println("<head><title>统计网站访问次数</title></head>");
out.println("<body>");
out.println("<h2><font color='gray'>");
out.println("您是第 "+context.getAttribute("counter")+" 位访客! ");
out.println("</font></h2>");
out.println("</body>");
out.println("</html>");
30.PNG
31.PNG
32.PNG
网友评论