码迷,mamicode.com
首页 > Web开发 > 详细

Servlet域对象ServletContext小应用------计算网站访问量

时间:2016-10-23 11:54:32      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:splay   open   访问量   class   rac   java   null   ase   tar   

技术分享
 1 package cn.yzu;
 2 import java.io.IOException;
 3 import java.io.PrintWriter;
 4 import javax.servlet.ServletContext;
 5 import javax.servlet.ServletException;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 
10 public class AServlet extends HttpServlet {
11 
12     public void doGet(HttpServletRequest request, HttpServletResponse response)
13             throws ServletException, IOException {
14         ServletContext application=this.getServletContext();
15         Integer count=(Integer) application.getAttribute("count");
16         if(count==null) 
17         {
18             count=1;
19             application.setAttribute("count",count);
20         }
21         else 
22             application.setAttribute("count",++count);
23         PrintWriter writer=response.getWriter();
24         writer.print("<h1>"+count+"</h1>");
25     }
26     public void doPost(HttpServletRequest request, HttpServletResponse response)
27             throws ServletException, IOException {
28         doGet(request, response);
29     }
30 }
View Code

 

Servlet域对象ServletContext小应用------计算网站访问量

标签:splay   open   访问量   class   rac   java   null   ase   tar   

原文地址:http://www.cnblogs.com/fengmingyue/p/5989146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!