zoukankan      html  css  js  c++  java
  • jsp request.getParameterValues获取数组值代码示例

    tt.jsp

    <form action="tt2.jsp" method="POST">
        <select name="two" multiple="multiple">
            <option value="val1" selected="selected">Value 1</option>
            <option value="val2" selected="selected">Value 2</option>
            <option value="val3" selected="selected">Value 3</option>
            <option value="val4" selected="selected">Value 4</option>
            <option value="val5" selected="selected">Value 5</option>
         </select>
         <input type="checkbox" name="three" value="chk1">Check 1<br/>
         <input type="checkbox" name="three" value="chk2">Check 2<br/>
         <input type="checkbox" name="three" value="chk3">Check 3<br/>
         <input type="checkbox" name="three" value="chk4">Check 4<br/>
         <input type="checkbox" name="three" value="chk5">Check 5<br/>
         
         <input type="submit" value="Submit">
    </form>

    tt2.jsp

    <%
    String[] selected = request.getParameterValues("two");
    if(selected != null){
        for(int i=0; i<selected.length; i++){
            out.write("<p>" + selected[i] + "<p>");
        }
    }else{
        out.write("<p> No value selected <p>");
    }
    
    String[] checked = request.getParameterValues("three");
    if(checked != null){
        for(int i=0; i<checked.length; i++){
            out.write("<p>" + checked[i] + "<p>");
        }
    }else{
        out.write("<p> No value checked <p>");
    }
    %>

    注意: 下拉多选框如果没有选中状态,rquest.getParameterValues是取不到值的~!

  • 相关阅读:
    js倒计时
    web前端基本开发手册
    快速了解CSS3当中的HSLA 颜色值怎么算
    IDEA快捷键
    3 认识的本质及其规律
    2 世界的物质性及其发展规律
    1 绪论
    9 数据库连接池
    8 代码实现事务
    7 IDEA连接数据库
  • 原文地址:https://www.cnblogs.com/simpledev/p/3516010.html
Copyright © 2011-2022 走看看