struts2中action得到选中的checkbox的值

来源:互联网 发布:人工智能对人类的好处 编辑:程序博客网 时间:2024/06/05 23:55

struts2中得到checkbox的值:

action中得到的是一个字符串,用","隔开。所以在action中定义一个属性值接收checkbox的name,然后拆串即可。

html:

Html代码  收藏代码
  1. <input type="checkbox" name="check" value="111">  
  2. <input type="checkbox" name="check" value="222">  
  3. <input type="checkbox" name="check" value="333">  

 action:

Java代码  收藏代码
  1. private String check;  
  2. //getter and setter..  
  3. String ids = this.getCheck();  
  4. System.out.println("ids::"+ids);  
  5. String[] arraycheck = ids.split(", ");  

 这样action就得到了checkbox的value值。

注意:action为我们取到得数组格式为[val1,  val2,   val3]的形式,逗号后边带个空格,所以用split拆分字符串的时候参数要传入", "而不是",",否则在遍历该数组的时候,只有val1的值取出是正确的。

原创粉丝点击