码迷,mamicode.com
首页 > Web开发 > 详细

jsp内置对象的使用

时间:2015-01-25 16:33:15      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

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内置对象的使用

标签:

原文地址:http://www.cnblogs.com/linhong/p/4248282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!