标签:src write too htm extend nod pbc rcv app
public class Aservlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获取ServletContext对象 //从对象中获取名为count的属性 //如果存在,给访问量+1,然后再保存回去 //如果不存在,说明时第一次访问,向ServletContext中保存count的属性,值为1 ServletContext app=this.getServletContext(); Integer count=(Integer) app.getAttribute("count"); if(count==null){ app.setAttribute("count", 1); }else{ app.setAttribute("count", count+1); } /** * 向浏览器输出,需要使用响应对象 */ PrintWriter pw=response.getWriter(); pw.print(count); } }
标签:src write too htm extend nod pbc rcv app
原文地址:https://www.cnblogs.com/fantongxue/p/11002081.html