request傳遞參數


當客戶請求時,Servlet容器創建SrevletRequest對象(用於封裝客戶的請求信息),這個對象將被容器作為service()方法的參數之一傳遞給Srevlet,Servlet可以利用ServletRequest對象獲取客戶端請求數據。

<form action="loing.do" method="post">
                <div>
                    <span>用戶名</span>
                    <div>
                        <input type="text" name="name" id="user" />
                    </div>
                    <span>密碼</span>
                    <div>
                        <input type="password" name="password" id="pw" />
                    </div>
                </div>
                    <div class="button">
                        <input type="submit" value=" 登 錄" class="submit">
                    </div>
            </form>

// 取得請求的參數
        String name = request.getParameter("name");
        String password = request.getParameter("password");

//用request傳遞參數

request.setAttribute("msg", "密碼錯誤,請重新輸入!");  

request.setAttribute("msg", "用戶" + name + "登錄成功");

<body>
    <c:if test="${not empty    requestScope.msg}"></c:if>
    <h1>${requestScope.msg}</h1>  獲取參數。
</body>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM