jsp request.getParameterValues获取数组值代码示例

tt.jsp

jsp request.getParameterValues获取数组值代码示例
<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>
jsp request.getParameterValues获取数组值代码示例

tt2.jsp

jsp request.getParameterValues获取数组值代码示例
<%
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>");
}
%>
jsp request.getParameterValues获取数组值代码示例

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

jsp request.getParameterValues获取数组值代码示例

上一篇:深入探究JavaScript对象系列(五)


下一篇:HTML-embed标签详解