jsp內建對象的使用

來源:互聯網
上載者:User

標籤:

request對象代表了用戶端的請求資訊,主要用於接受通過HTTP協議傳送到伺服器的資料。

<form action="request.jsp" method="post">        <table>            <tr>                <td>username:</td>                <td><input type="text" name="username" value=""></td>            </tr>            <tr>                <td>hobby:</td>                <td><input type="checkbox" name="favor" value="basket">basketball</td>                <td><input type="checkbox" name="favor" value="football">football</td>                <td><input type="checkbox" name="favor" value="eat">eatting</td>            </tr>            <tr>                <td colspan="2"><input type="submit" value="SubMit">                </td>            </tr>        </table>    </form>
//request.jsp 
<%--request處理中文亂碼問題 --%> <% request.setCharacterEncoding("utf-8");//解決字元亂碼問題,對post有效 request.setAttribute("password", "admin");//儲存一些屬性的值 %> <%--request擷取form表單的資訊 --%> username:<%=request.getParameter("username") %><br/> hobby:<% if(request.getParameterValues("favor")!=null) { String []hobby=request.getParameterValues("favor"); for(String s:hobby) { out.println(s); } } %> password:<%=request.getAttribute("password") %><br/> <hr/> <%--request獲得用戶端的一些資訊 --%> 獲得請求的頁面類型:<%=request.getContentType() %><br/> 獲得請求的協議版本:<%=request.getProtocol() %><br/> 獲得請求的伺服器名字:<%=request.getServerName() %><br/> 獲得請求的伺服器連接埠號碼:<%=request.getServerPort() %><br/> 獲得用戶端ip地址: <%=request.getRemoteAddr() %><br/>

 

jsp內建對象的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.