application在整个WEB项目中共享使用数据。

常用方法:
 getAttribute();
 setAttribute();
示列:

 

 <%
    Object count=application.getAttribute("count");
    if(count==null){
     //application中未存放count
     application.setAttribute("count", new Integer(1));
    }else{
     //application中已经存放count
     Integer i=(Integer)count;
     application.setAttribute("count", i.intValue()+1);
    }
    Integer icount=(Integer)application.getAttribute("count");
    out.println("页面被访问了"+icount.intValue()+"次");
    %>

 

可以直接将此段代码放在需要显示的JSP页面中。

相关文章:

  • 2021-11-18
  • 2021-12-10
  • 2021-12-11
  • 2021-05-14
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
猜你喜欢
  • 2022-12-23
  • 2021-06-17
  • 2021-06-15
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案