<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 中的`request`隱式對象 > 原文: [https://beginnersbook.com/2013/11/jsp-implicit-object-request-with-examples/](https://beginnersbook.com/2013/11/jsp-implicit-object-request-with-examples/) 這里我們將討論 JSP 中的`request`隱式對象。它主要用于獲取用戶在之前的 JSP 頁面上輸入的 JSP 頁面上的數據。 ### `request`隱式對象的方法 1. `getParameter(String name)` - 此方法用于獲取請求參數的值。例如,在登錄頁面,用戶輸入用戶 ID 和密碼,一旦驗證了憑證,登錄頁面就會被重定向到用戶信息頁面,然后使用`request.getParameter`我們可以獲得用戶在登錄頁面輸入的用戶 ID 和密碼的值。 ```html String Uid= request.getParameter("user-id"); String Pass= request.getParameter("password"); ``` 2. `getParameterNames()` - 它返回與請求關聯的所有參數名稱的枚舉。 ```html Enumeration e= request.getParameterNames(); ``` 3. `getParameterValues(String name) - 它返回參數值數組。 ```html String[] allpasswords = request.getParameterValues("password"); ``` 4. `getAttribute(String name)` - 用于獲取屬性值。`request.getAttribute("admin")`將為您提供屬性`admin`的值。 5. `getAttributeNames()` - 它通常用于獲取與當前會話關聯的屬性名稱。它返回會話中存在的屬性名稱的枚舉。 ```html Enumerator e = request.getAttributeNames(); ``` 6. `setAttribute(String, Object)` - 它將一個對象的值賦給該屬性。例如,我有一個屬性`password`和一個`String`對象`str`,其值為`"admin"`然后調用`request.setAttribute("password", str)`將賦值`admin`到屬性`password`。 7. `removeAttribute(String)` - 通過使用此方法,可以刪除屬性,不能進一步使用。對于例如如果在 JSP 頁面上有聲明`request.removeAttribute("userid")`,那么`userid`屬性將被完全刪除,而在`removeAttribute`方法之后使用`request.getAttribute("userid")`將返回 **NULL** 。 8. `getCookies()` - 它返回從客戶端收到的 cookie 對象數組。此方法主要用于處理 JSP 中的 cookie。 9. `getHeader(String name)` - 此方法用于獲取請求的頭信息。 10. `getHeaderNames()` - 返回所有標題名稱的枚舉。下面的代碼片段將顯示與請求關聯的所有標頭名稱。 ```html Enumeration e = request.getHeaderNames(); while (enumeration.hasMoreElements()) { String str = (String)e.nextElement(); out.println(str); } ``` 11. `getRequestURI()` - 此方法(`request.getRequestURI()`)返回當前 JSP 頁面的 URL。 12. `getMethod()` - 它返回 HTTP 請求方法。`request.getMethod()`。例如,它將為`Get`請求返回`GET`,為`Post`請求返回`POST`。 13. `getQueryString()` - 用于獲取與 JSP 頁面 URL 關聯的查詢字符串。它是在問號符號(`?`)后與 URL 相關聯的字符串。 ### `request`隱式對象示例 在下面的示例中,我們在`index.html`頁面中接收來自用戶的輸入,并使用`request`隱式對象在`userinfo.jsp`頁面中顯示相同的信息。 `index.html` ```html <html> <head> <title>Enter UserName and Password</title> </head> <body> <form action="userinfo.jsp"> Enter User Name: <input type="text" name="uname" /> <br><br> Enter Password: <input type="text" name="pass" /> <br><br> <input type="submit" value="Submit Details"/> </form> </body> </html> ``` `userinfo.jsp` ```html <%@ page import = " java.util.* " %> <html> <body> <% String username=request.getParameter("uname"); String password=request.getParameter("pass"); out.print("Name: "+username+" Password: "+password); %> </body> </html> ``` **上述例子的快照** 一旦運行上面的 JSP 代碼。它會顯示以下屏幕,其中包含兩個用戶名和密碼的文本字段。 ![LoginPage](https://img.kancloud.cn/31/54/31548650d585545bfe53d41dbb8520d6_593x305.jpg) 這是`userinfo.jsp`頁面的輸出。這里我們獲取了用戶在登錄頁面中輸入的 id 和密碼。 ![UserInfoPage](https://img.kancloud.cn/b3/2e/b32edfd0694b671983f4f81d5347e056_593x305.jpg) 如果您對 JSP `request`隱式對象有任何疑問,請告訴我們。我們很樂意幫助您!!
                  <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>

                              哎呀哎呀视频在线观看