jsp_屬性範圍_application

來源:互聯網
上載者:User

標籤:log   ext   charset   name   pre   html   dem   姓名   不同   

如果希望設定一個屬性,可以讓所有使用者看得見,則可以將屬性範圍設定成application,這樣屬性即可以儲存在伺服器上。

下面寫一個小例子來驗證一下:

(1)application_demo.jsp

 1 <%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*" errorPage="" %> 2 <!doctype html> 3 <html> 4 <head> 5 <meta charset="utf-8"> 6 <title>application屬性範圍</title> 7 </head> 8  9 <body>10     <%11         application.setAttribute("name","lisi");12         application.setAttribute("birthday",new Date());13     %>14     <a href="application_demo2.jsp">通過超連結取得屬性</a>15 </body>16 </html>

(2)application_demo2.jsp

 1 <%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*" errorPage="" %> 2 <!doctype html> 3 <html> 4 <head> 5 <meta charset="utf-8"> 6 <title>application屬性範圍</title> 7 </head> 8  9 <body>10     <%11         String name=(String)application.getAttribute("name");12         Date birthday=(Date)application.getAttribute("birthday");13     %>14     <h2>姓名:<%=name%></h2>15     <h2>生日:<%=birthday%></h2>16 </body>17 </html>

瀏覽器顯示:(此時我們開啟兩個不同的瀏覽器)

        

註:application範圍的屬性設定過多會影響伺服器效能。

jsp_屬性範圍_application

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.