public class Emp implements java.io.Serializable
{
private String name;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
public class EmpForm extends ActionForm{
     private List empList = new ArrayList();
     public List getEmpList(){return this.empList;}
     public void setEmpList(List empList)
     {
        this.empList = empList;
    }
}
public class EmpAction extends Action
{
   public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) 
  {
      EmpForm empForm = (EmpForm) form;
      if ("list".equals(empForm.getType())){
         empFrom.setEmpList(EmpService.allEmp());//从数据库中取出
          return mapping.findForward("list");
       }
       else{
           EmpService.saveEmp(empForm.getEmpList());
           rerturn mapping.findForward("save"); 
     }
  }
}
从数据库中取出Emp对象显示在页面上像这样
姓名           性别            年龄  添加
张三            男              20
李四             男             21
....
保存
点添加按钮时用javascript动态生成一行,文本框,下拉框,文本框,让用户输入.我点保存时怎样才能将上面的信息放进empList中呢?

解决方案 »

  1.   

    你的form应该没有问题 可以尝试一下页面上这么写:<logic:notEmpty name="empListForm" >
        <bean:define id="list" name="empListForm" property="empList"/>
        <logic:empty name="list">
         <bean:message key="message.system.empty"/>
        </logic:empty>
        <logic:iterate id="s" name="list">
         ${s.name}-----${s.sex}
        </logic:iterate>
        <br/>
        ${page.toolBar }
        </logic:notEmpty>
      

  2.   

     <logic:iterate id="Emp" name="FORM名" property="resultList" type="List里装的CLASS类型" indexId="index">
    <bean:write name ="Emp"  property="name" />
       </logic:iterate>