首页 > Web开发 > 详细

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

时间:2014-01-15 23:58:10      阅读:631      评论:0      收藏:0      [点我收藏+]

tt.jsp

bubuko.com,布布扣
<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>
bubuko.com,布布扣

tt2.jsp

bubuko.com,布布扣
<%
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>");
}
%>
bubuko.com,布布扣

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

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

原文:http://www.cnblogs.com/simpledev/p/3516010.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!