package servletcontext;
import java.io.IOException;
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 ServletA extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ServletContext sc=this.getServletContext();
//通过域属性名获取域属性值count
Integer count=(Integer)sc.getAttribute("time");
//判断,这个值是不是为null,如果不是就加1;如果是,说明第一次被访问,就为1
if(count==null){
sc.setAttribute("time",1);
}else{
sc.setAttribute("time", count+1);
}
//像浏览器打印需要用到打印流,响应体resp提供了这个方法
PrintWriter pw=resp.getWriter();
pw.print(count);
}
}
用dynatrace查看网站实时访问量
你只是对context中的time对应的count做了处理,而你要输出的count并没有被处理