读书人

HttpSession兑现计数

发布时间: 2012-12-21 12:03:49 作者: rapoo

HttpSession实现计数

?

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");PrintWriter out=response.getWriter();HttpSession session=request.getSession();Object count=session.getAttribute("COUNT");int counter=0;if (count==null) {counter=1;session.setAttribute("COUNT",new Integer(1));}else{counter=((Integer)count).intValue();counter++;session.setAttribute("COUNT", new Integer(counter));}out.print("访问了"+counter+"次!");}

读书人网 >编程

热点推荐