struts2 list 迭代输出 到页面后 在页面修改其中的一些值 再提交到 后台 如何得到修改后的list


转至csdn问答区
页面初始化的action将peopleList存放到session作用域中,页面文本框的name为ages,点击保存时,ages的值字段会字段封装到String[] ages数组。

保存的action代码可以参考如下代码:
Java code
public class InitAction extends ActionSupport implements ServletRequestAware
{
    private HttpServletRequest request;
    private String[] ages;

    public void setAges(String[] ages){
        this.ages=ages;
    }

    public String[] getAges(){
        return ages;
    }

  public String exceute(){
        //从session中取出peopleList
        HttpSession session = request.getSession();
        List peopleList = (List)session.getAttribute("peopleList");

        for(int i=0;i<peopleList.size();i++){
            People people = (People)peopleList.get(i);
            people.setAge(Integer.valueOf(ages[i]));//赋值
        }

        //peopleList就为修改后的List
            return SUCCESS;
    }
   


     public HttpServletRequest getRequest() {
        return request;
    }

    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
       

你可能感兴趣的:(struts2)