一、JSP中
①集合为list
<s:checkboxlist name="list" list="{'Java','.Net','RoR','PHP'}" value="{'Java','.Net'}" />生成html
<input type="checkbox" name="list" value="Java" checked="checked" /><label>Java</label>
<input type="checkbox" name="list" value=".Net" checked="checked" /><label>.Net</label>
<input type="checkbox" name="list" value="RoR" /><label>RoR</label>
<input type="checkbox" name="list" value="PHP" /><label>PHP</label>
②集合为MAP
<s:checkboxlist name="map" list="#{1:'瑜珈用品',2:'户外用品',3:'球类',4:'自行车'}"
listKey="key" listValue="value" value="{1,2,3}" />
生成html
<input type="checkbox" name="map" value="1" checked="checked" /><label>瑜珈用品</label><input type="checkbox" name="map" value="2" checked="checked" /><label>户外用品</label>
<input type="checkbox" name="map" value="3" checked="checked" /><label>球类</label>
<input type="checkbox" name="map" value="4" /><label>自行车</label>
③集合里存放javabean(id和name为Person的属性)
<%
Person person1 = new Person(1, "小明");
Person person2 = new Person(2, "小红");
List<Person> list = new ArrayList<Person>();
list.add(person1);
list.add(person2);
request.setAttribute("persons", list);
request.setAtttibute("pchecked",person1);
%>
<s:checkboxlist name="beans" list="#request.persons"
listKey="id" listValue="name" value="#request.pchecked.id" />
生成html
<input type="checkbox" name="beans" value="1" checked="checked" /><label>小明</label>
<input type="checkbox" name="beans" value="2" /><label>小红</label>
二、Action中
可以定义集合或数组接收值,比如定义List<Integer>可以接收上面③传来的值。
原帖详细讲了radio和select的用法,地址:http://wenku.baidu.com/view/caae743610661ed9ad51f384.html