zoukankan      html  css  js  c++  java
  • JAVA-JSP内置对象之session范围

     

    相关资料:
    《21天学通Java Web开发》

    session范围
    1.就是指客户浏览器与服务器一次会话范围内,如果和服务器断开连接,那么这个属性也就失效了。
    2.通过使用session的setAttribute()方法来设置属性,并通过session的getAttribute()方法来取得属性。
    3.如果同时打开多个浏览器,那结果可能不同。

     

    SessionScopeDemo.jsp

     1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>session范围</title>
     5 </head>
     6 <body>
     7   <%-- 在session范围设置属性 --%>
     8   <%
     9     session.setAttribute("name","James");//设置属性name,其值为James  
    10   %>
    11   <%-- 添加页面链接,用来跳转到SessionScopeDemo2.jsp --%>
    12   <a href="SessionScopeDemo2.jsp">SessionScopeDemo2.jsp</a>
    13 </body>
    14 </html>
    View Code

     

    SessionScopeDemo2.jsp

     1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>session范围</title>
     5 </head>
     6 <body>
     7   <%-- 取得session范围属性 --%>
     8   <%
     9     String strName=(String)session.getAttribute("name");//取得属性name的值
    10     out.println("session范围:name属性值为"+strName);//输出属性name的值 
    11   %>
    12 </body>
    13 </html>
    View Code
  • 相关阅读:
    拓扑排序
    Codeforces #503 C. Elections(贪心,逆向
    Codeforces #367 (Div. 2) D. Vasiliy's Multiset (trie 树)
    字典树
    最大子段和
    P1880 [NOI1995] 石子合并
    P1140 相似基因
    P1280 尼克的任务
    [BZOJ4064/Cerc2012]The Dragon and the knights
    [BZOJ4066]简单题
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/7665057.html
Copyright © 2011-2022 走看看