<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # JSP 中的`Session`隱式對象 > 原文: [https://beginnersbook.com/2013/11/jsp-implicit-object-session-with-examples/](https://beginnersbook.com/2013/11/jsp-implicit-object-session-with-examples/) `Session`是 JSP 中最常用的隱式對象。它的主要用途是訪問所有用戶的數據,直到用戶會話處于活動狀態。 ### `session`隱式對象的方法 1. `setAttribute(String, object)` - 此方法用于通過為對象分配唯一字符串來保存會話中的對象。之后,可以使用相同的`String`從會話中訪問該對象,直到會話處于活動狀態。`setAttribute`和`getAttribute`是在 JSP 中處理會話時最常用的兩種方法。 2. `getAttribute(String name)` - `setAttribute`方法存儲的對象是使用`getAttribute`方法從`session`獲取的。例如,如果我們需要訪問每個 jsp 頁面上的`userid`,直到會話處于活動狀態,那么我們應該使用`setAttribute`方法將`user-id`存儲在會話中,并且可以在需要時使用`getAttribute`方法進行訪問。 3. `removeAttribute(String name)` - 可以使用此方法從會話中刪除存儲在會話中的對象。將唯一字符串標識符作為`removeAttribute`的方法傳遞。 4. `getAttributeNames` - 它返回會話中存儲的所有對象。基本上,它會導致對象的枚舉。 5. `getCreationTime` - 此方法返回會話創建時間,即會話啟動的時間(變為活動狀態)。 6. `getId` - Servlet 容器在創建會話時為會話分配唯一??的字符串標識符。`getId`方法返回該唯一字符串標識符。 7. `isNew()` - 用于檢查會話是否是新的。它返回布爾值(`true`或`false`)。主要用于跟蹤客戶端是否啟用了 cookie。如果禁用 cookie,`session.isNew()`方法將始終返回`true`。 8. `invalidate()` - 它會終止會話并中斷會話與所有存儲對象的關聯。 9. `getMaxInactiveInterval` - 以秒為單位返回會話的最大停用時間間隔。 10. `getLastAccessedTime` - 通常用于知道會話的最后訪問時間。 ### `session`隱式對象示例 下面的 HTML 頁面將顯示一個文本框和一個提交按鈕。提交操作會將控件轉移到`session.jsp`頁面。 index.html ```html <html> <head> <title>Welcome Page: Enter your name</title> </head> <body> <form action="session.jsp"> <input type="text" name="inputname"> <input type="submit" value="click here!!"><br/> </form> </body> </html> ``` `session.jsp`頁面顯示用戶在索引頁面中輸入的名稱,它將相同的變量存儲在`session`對象中,以便可以在任何頁面上獲取它,直到會話變為非活動狀 `session.jsp` ```html <html> <head> <title>Passing the input value to a session variable</title> </head> <body> <% String uname=request.getParameter("inputname"); out.print("Welcome "+ uname); session.setAttribute("sessname",uname); %> <a href="output.jsp">Check Output Page Here </a> </body> </html> ``` 在這個頁面中,我們從`session`對象中獲取變量的值并顯示它。 `output.jsp` ```html <html> <head> <title>Output page: Fetching the value from session</title> </head> <body> <% String name=(String)session.getAttribute("sessname"); out.print("Hello User: You have entered the name: "+name); %> </body> </html> ``` **輸出屏幕** ![jsp-welcome-page](https://img.kancloud.cn/c7/11/c711a85b09ad578cd5b614370105832c_574x322.jpg) ![User-jsp-page](https://img.kancloud.cn/ce/3b/ce3b22d9545799f5432d2c603a0d5d5e_574x322.jpg) ![output-screen](https://img.kancloud.cn/bd/42/bd424f0cdf191bcbf292f4fc110a7d6a_574x322.jpg)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看