zoukankan      html  css  js  c++  java
  • 后台获得数据

     1 <body>
     2     
     3     <form action = "do_post.jsp" method = "post">
     4     
     5     用户名:<input type = "text" id = "" name = "user">
     6     <br>
     7     密码:&nbsp;<input type = "password" id = "" name = "pass">
     8     <br>
     9     性别:
    10     <br>
    11<input type = "radio" id = "" name = "sex" value = "nan"> &nbsp; 
    12<input type = "radio" id = "" name = "sex" value = "nv">
    13     <br>
    14     个人说明:
    15     <br>
    16     <textarea rows="4" cols="35" id = "" name = "text"></textarea>
    17     <br>
    18     <input type = "submit" value = "提交">
    19     </form>
    20     
    21 </body>

    对于这些输入或单选都可以使用普遍输出:

     1 <body>
     2 <%
     3     String user = request.getParameter("user");
     4     request.setAttribute("user", user);
     5     
     6     String pass = request.getParameter("pass");
     7     request.setAttribute("pass", pass);
     8     
     9     String sex = request.getParameter("sex");
    10     request.setAttribute("sex", sex);
    11     
    12     String text = request.getParameter("text");
    13     request.setAttribute("text", text);
    14 %>
    15 
    16 <p>${user }</p>
    17 <p>${pass }</p>
    18 <p>${sex }</p>
    19 <p>${text }</p>
    20 </body>

    而多选框因为多选,输出的是一个数组,所以:

    1     <body>
    2     爱好:
    3     <br>
    4     骑行<input type = "checkbox" id = "" name = "favorite" value = "qixing">
    5     爬山<input type = "checkbox" id = "" name = "favorite" value = "pashan">
    6     游泳<input type = "checkbox" id = "" name = "favorite" value = "youyong">
    7     蹦极<input type = "checkbox" id = "" name = "favorite" value = "bengji">
    8     </body>
    1 <body>
    2 String favorite[] = request.getParameterValues("favorite");
    3 request.setAttribute("favorite", favorite);
    4 <%
    5 for(String a : favorite){
    6 %>
    7 <%=a %>
    8 <%}%>
    9 </body>

    补充:

    req.setCharacterEncoding("utf-8"); 改变编码格式

  • 相关阅读:
    [转]Java中的回车换行符/n /r /t
    [转]jquery.validate.js表单验证
    [转]PowerDesigner中name和code取消自动关联
    Oracle 执行报错表空间或临时表空间不足,降低水位线方法
    cookie实现自动登录
    linux 进程管理相关内容
    招银网络科技面试
    唯品会面试被虐
    sql查询最大的见多了,查询第二的呢???
    HashMap的key可以是可变的对象吗???
  • 原文地址:https://www.cnblogs.com/shenhx666/p/8046051.html
Copyright © 2011-2022 走看看