本帖最后由 andymu077 于 2011-08-07 16:53:56 编辑

解决方案 »

  1.   

    这个不是和参数的提交是一样的道理吗,你一个或多个参数提交的时候,在action中不也是用相对应的参数接收,而一个list你也可以把它看做是一个参数,在action中声明一个list接收它就好了呀……
      

  2.   

    可是从form的list变量。边取出来的却是null,不知道为什么呀!
      

  3.   

    在action中声明一个list 得到所有lstTblId文本框的值 在进行循环把每一个值添加到list中
      

  4.   

    1.你遍历的部分是否在<html:form action.../>中
    2.你返回的值不会是以list的形式返回的而可能是String[] strTblId ,String[] strTblName
      

  5.   

    lz你为啥要把list传到action呢,你可以在action中封装哇。jsp只是显示的,不要设计太多的东西
      

  6.   

    这个用于显示的list,做成了textbox。修改之后再提交。在下一个Action中需要获取里边的修改值!
      

  7.   


    项目太多了。所以我想是不是可以一次将整个ListBean传到Action中!也就是这个list对象传到JSP中之后还可以一个List对象的方式传递到Action使用。
      

  8.   

    把前台的数据封装成list??这不是自找麻烦吗?!formbean对应不好用吗?
      

  9.   


    问题是真的不好用。提交到Action里边Form里边的list对象是null
      

  10.   


    表单里边的list取得的是null,你可以试一下
      

  11.   


    <body><%String id= request.getParameter("id");
    String action = id!=null?"emp.do?method=update":"emp.do?method=create";
    %><html:form action="<%= action%>">
    <html:hidden name="empForm" property="id"/>
    NAME:<html:text name="empForm" property="name" />
    BIRTHDAY: <html:text name="empForm" property="birthday" />
    ADDRESS: <html:text name="empForm" property="address" />
    EMAIL:<html:text name="empForm" property="email" />
    <html:submit/>
    <html:reset/>
    </html:form>
    </body>public class EmpAction extends DispatchAction{
    private final static String SUCCESS = "success";
        
    //EmpService service = new EmpServiceImpl();

    @Resource EmpService empService;

     public ActionForward find(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
     Collection emps= empService.find();
     request.setAttribute("emps", emps);
     return mapping.findForward(SUCCESS);        
     }
     public ActionForward input(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
     String id = request.getParameter("id");
     if(id!=null){
     Emp emp = empService.load(id);
     EmpForm empForm = (EmpForm) form;
     empForm.setId(emp.getId());
     empForm.setName(emp.getName());
     empForm.setBirthday(emp.getBirthday());
     empForm.setAddress(emp.getAddress());
     empForm.setEmail(emp.getEmail()); 
     }
     return mapping.findForward("input");        
     }
     
     
     public ActionForward create(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
     EmpForm empForm = (EmpForm)form;
     Emp emp = new Emp();
     emp.setId(empForm.getId());
     emp.setName(empForm.getName());
     emp.setBirthday(empForm.getBirthday());
     emp.setAddress(empForm.getAddress());
     emp.setEmail(empForm.getEmail());
     empService.create(emp);
     Collection emps= empService.find();
     request.setAttribute("emps", emps);
     return mapping.findForward(SUCCESS);        
     }
     
     public ActionForward update(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
     EmpForm empForm = (EmpForm)form;
     Emp emp = new Emp();
     emp.setId(empForm.getId());
     emp.setName(empForm.getName());
     emp.setBirthday(empForm.getBirthday());
     emp.setAddress(empForm.getAddress());
     emp.setEmail(empForm.getEmail());
     empService.update(emp);
     Collection emps= empService.find();
     request.setAttribute("emps", emps);
     return mapping.findForward(SUCCESS);        
     }
     
     public void setService(EmpService empService) {
    this.empService = empService;
    }
     

    }
    public class EmpForm extends org.apache.struts.action.ActionForm{

    String id;
    String name;
    String birthday;
    String address;
    String email;
    public String getId() {
    return id;
    }
    public void setId(String id) {
    this.id = id;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getBirthday() {
    return birthday;
    }
    public void setBirthday(String birthday) {
    this.birthday = birthday;
    }
    public String getAddress() {
    return address;
    }
    public void setAddress(String address) {
    this.address = address;
    }
    public String getEmail() {
    return email;
    }
    public void setEmail(String email) {
    this.email = email;
    }}