首页 > 其他 > 详细

Servlet 实现訪问量的统计小案例

时间:2018-02-25 16:45:42      阅读:208      评论:0      收藏:0      [点我收藏+]

  今天学习了Servlet的基础知识,学习了一个统计訪问量的小案例,记录一下

package cn.selevet_01;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Servlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	 ServletContext sc = this.getServletContext();
	    Integer ct=(Integer)sc.getAttribute("count");
	    if(ct==null)
	    {
	    	sc.setAttribute("count", 1);
	    }
	    else{
	    	sc.setAttribute("count", ct+1);
	    }
	    System.out.println("訪问量为:"+sc.getAttribute("count"));
	}


}


Servlet 实现訪问量的统计小案例

原文:https://www.cnblogs.com/zhchoutai/p/8469618.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!