读书人

()关于j2ee中application的setAttri

发布时间: 2013-10-29 12:07:57 作者: rapoo

(求助)关于j2ee中application的setAttribute不能创建值


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

response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
ServletContext application=this.getServletContext();

Integer accessCount=(Integer) application.getAttribute("accessCount");
if(accessCount==null)
accessCount=0;
else
accessCount=accessCount+1;

application.setAttribute("accessCouunt", accessCount);

out.println(accessCount);

}


经过我的调试,我发现accessCount的值永远都是null值,这到底是怎么回事啊?
为什么下面的application.setAttribute()不创建呢? application j2ee
[解决办法]
application.setAttribute("accessCouunt", accessCount);
//这里变量名不对,应该是accessCount

读书人网 >Java Web开发

热点推荐