public class TestForm extends ActionForm {
/*
* Generated fields
*/
/** sex property */
private String sex;
/** favorite property */
private String favorite[];
/** name property */
private String name;
由于是复选,所以favorite设置成[]类型;
ACTION处理:
public ActionForward saveTest(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
TestForm testForm = (TestForm) form;// TODO Auto-generated method stub
System.out.println(testForm.getName());
System.out.println(testForm.getSex());
String favor[]=testForm.getFavorite();
String result="";
for(int i=0;i<favor.length;i++)
{
result=result+favor[i]+",";
}
result=result.substring(0, result.length()-1); System.out.println(result);
WebApplicationContext appContext = this.getWebApplicationContext();
TestDAO t = (TestDAO)appContext.getBean("TestDAO");
Test te=new Test();
te.setName(testForm.getName());
te.setSex(testForm.getSex());
te.setFavorite(result);
t.save(te);
return null;
}
public ActionForward findTest(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
TestForm testForm = (TestForm) form;// TODO Auto-generated method stub
Test te=new Test();
te.setName("男");
te.setSex("女");
te.setFavorite("天天,学习");
String re[]=te.getFavorite().split(",");
testForm.setFavorite(re); testForm.setName(te.getName());
testForm.setSex(te.getSex());
return mapping.findForward("edit_test_Ok");
}
}