• 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是取不到值的~!

  • 相关阅读:
    C++中的explicitkeyword
    Stream使用教程
    Java实现最长回文串
    Java实现最长回文串
    Java实现最长回文串
    Java实现选择问题
    Java实现选择问题
    Java实现选择问题
    Java实现选择问题
    Java实现选择问题
  • 原文地址:https://www.cnblogs.com/simpledev/p/3516010.html
Copyright © 2020-2023  润新知