• struts标签处理checkbox

    2011-02-19

    页面testCheckbox.jsp代码: <input name="test" type="checkbox" checked="checked" value="1"/> <input name="test" type="checkbox" value="2"/> <input name="test" type="checkbox" checked="checked" value="3"/> 页面数据接收action:TestCheckboxAction.action 1、struts接收页面上一列checkbox选择结果 在TestCheckboxAction.action中使用private int[] test;定义一个数组并定义起对应的get/set方法,来处理页面传来的数据,对应页面中name为test的checkbox。 此时在action中System.out.print(Arrays.asList(test).toString());,可以看到控制台输出为[1,3],表明当前选中的是1和3。而如果database中要同时记录这三个checkbox的选择情况,该如何处理? 可以另外定义一个长度为3的数组,checkbox[] = {"0", "0", "0};,根据页面选择的情况更改checkbox的值。 if (null != getTest()) {     for (int d : getTest())         checkbox[d - 1] = "1"; } 2、页面显示数据库中对checkbox的记录 <s:checkboxlist list="{’1′,’2′,’3′}" value="testList" theme="simple" name="test" /> 在TestCheckboxAction.action定义List<String> testList来记录数据库的查询结果,此时testList的长度应该为3。

 
Powered by Wordpress. Theme by Shlomi Noach  京东商品折扣