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是取不到值的~!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。