zoukankan      html  css  js  c++  java
  • java内置对象生命周期

    JSP 内置对象作⽤域

        4个
        page、request、session、application
       公共方法:setAttribute、getAttribute
     
    page 作⽤域:对应的内置对象是 pageContext。
    request 作⽤域:对应的内置对象是 request。
    session 作⽤域:对应的内置对象是 session。
    application 作⽤域:对应的内置对象是 application。
    page < request < session < application
     
    page 只在当前⻚⾯有效。
    request 在⼀次请求内有效。
    session 在⼀次会话内有效。
    application 对应整个 WEB

    page

     request

    session

    会话内可以有无数个请求

     application

    只有tomcat关了才失效

    一个例子,网站浏览量记录

    1.永远显示1

    <%
        int count=0;
        count++;
    %>
    您是当前的第<%=count%>位访客

    2.永远显示1

    <%
        Integer count=(Integer) request.getAttribute("count");
        if(count== null){
            count=1;
            request.setAttribute("count",count);
        }else {
            count++;
            request.setAttribute("count",count);
        }
    %>
    您是当前的第<%=count%>位访客

    原因:刷新后request没了,永远都是count=null,变成1

    3.能正确显示的

    <%
        Integer count=(Integer) session.getAttribute("count");
        if(count== null){
            count=1;
            session.setAttribute("count",count);
        }else {
            count++;
            session.setAttribute("count",count);
        }
    %>
    您是当前的第<%=count%>位访客

     但在不同浏览器中数据不同

    所以用application

    <%
        Integer count=(Integer) application.getAttribute("count");
        if(count== null){
            count=1;
            application.setAttribute("count",count);
        }else {
            count++;
            application.setAttribute("count",count);
        }
    %>
    您是当前的第<%=count%>位访客
  • 相关阅读:
    域名、主机名、网站名以及 URL 基础概念
    c# oracle 数据库连接以及参数化查询
    c# 委托(Func、Action)
    xcode pod install 安装失败,提示缺少文件
    一个服务器的IIS只能绑定一个HTTPS也就是443端口
    APP UI设计及切图规范
    Day7 字符串和常用数据结构
    Day6 函数和模块的使用
    Day5 练习
    python 疑难杂症
  • 原文地址:https://www.cnblogs.com/hanabi-521/p/14316833.html
Copyright © 2011-2022 走看看