JSP 表单request内容

1. 表单request内容的获取

2. request.setCharacterEncoding("utf-8")对request内容进行编码

3. fullformrequest.jsp 提交表单 showrequest.jsp 显示request内容

<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%
    request.setCharacterEncoding("utf-8");
%>
<html>
    <head>
        <title>
            full form request
        </title>
    </head>

    <body>
        <center>
            <h1>
                全量的表单提交
            </h1>
            </br>
            </br>
            <form action="showRequest.jsp" method="post">
                <table id="fullTable">
                    <tr>
                        <td>用户名:</td>
                        <td><input type="text" name="name"/></td>
                    </tr>
                    <tr>
                        <td>昵称:</td>
                        <td><input type="text" name="nickname"/></td>
                    </tr>
                    <tr>
                        <td>
                            性别:
                        </td>
                        <td>
                            <input type="radio" name="sex" value="male" checked/>male
                            <input type="radio" name="sex" value="female"/>female
                        </td>
                    </tr>
                    <tr>
                        <td>城市</td>
                        <td><select name="city" id="">
                                <option value="上海">上海</option>
                                <option value="杭州">杭州</option>
                                <option value="北京">北京</option>
                                <option value="深圳">深圳</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>爱好:</td>
                        <td>
                            <input type="checkbox" name="intrist" value="唱歌"/>唱歌
                            <input type="checkbox" name="intrist" value="跳舞"/>跳舞
                            <input type="checkbox" name="intrist" value="运动"/>运动
                            <input type="checkbox" name="intrist" value="读书"/>读书
                        </td>
                    </tr>
                    <tr>
                        <td>
                            自我介绍:
                        </td>
                        <td>
                            <textarea name="selfintr" cols="30" rows="10"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td><input type="submit"></td>
                        <td><input type="reset"></td>
                    </tr>
                </table>
            </form>

        </center>
    </body>

</html>
<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%
    request.setCharacterEncoding("utf-8");
%>
<html>
    <head>
        <title>
            show request
        </title>
    </head>

    <body>
        <center>
            <h1>
                表单提交的值
            </h1>
            <%
                String name=request.getParameter("name");
                String nickname=request.getParameter("nickname");
                String sex=request.getParameter("sex");
                String city=request.getParameter("city");
                String[] intrist=request.getParameterValues("intrist");
                String selfintr=request.getParameter("selfintr");
            %>
            <table>
                <tr>
                    <td>名字:<%=name%></td>
                </tr>
                <tr>
                    <td>昵称:<%=nickname%></td>
                </tr>
                <tr>
                    <td>
                        性别:<%=sex%>
                    </td>
                </tr>
                <tr>
                    <td>
                        城市:<%=city%>
                    </td>
                </tr>
                <tr>
                    <td>
                        爱好:
                        <%
                                if(intrist!=null)
                                {
                                    for(int i =0; i< intrist.length; i++)
                                    {
                        %>
                                <%=intrist[i]%>
                        <%
                                    }
                                }
                        %>
                    </td>
                </tr>
                <tr>
                    <td>
                        自我介绍:<%=selfintr%>
                    </td>
                </tr>
                
            </table>
            
            
        </center>
    </body>

</html>

 

 

posted @ 2013-07-07 14:11  holycrap  阅读(531)  评论(0编辑  收藏  举报