struts2 checkboxlist赋值的问题

checkboxlist 可以选择多个值, 在action中用string型接值时接到的是像这样的值 A,B,C

面从DB中往页面写给checkboxlist赋值则要求这么写

Action中:

 private String[] selQuestionAnswer = null;

/**
* @return the selQuestionAnswer
*/
public String[] getSelQuestionAnswer() {
return selQuestionAnswer;
}

/**
* @param selQuestionAnswer the selQuestionAnswer to set
*/
public void setSelQuestionAnswer(String[] selQuestionAnswer) {
this.selQuestionAnswer = selQuestionAnswer;
}

action中赋值 ,要这么写,也就是把值用split的方式,转成数组

this.setSelQuestionAnswer(bean.getQUESTION_ANSWER().split("|"));

JSP中:

<s:checkboxlist value ="selQuestionAnswer" theme="simple" name="questionAnswer"

      list="questionAnswerList8c" listKey="key" listValue="value"></s:checkboxlist>

主要是这个value的值,必须是String[] 型才能赋上多个值,否则只能把一个checkbox check上

原文地址:https://www.cnblogs.com/lost0/p/2987640.html