UserInfo bean 相关属性
public class UserInfo{
 
private String username;
private String password; public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
}
}单个的UserInfopublic class UserInfoForm  extends ActionForm { private static final long serialVersionUID = 1L;
private String username;
private String password; public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
}
}多个的UserInfo
public class UserInfoListForm  extends ActionForm{

private static final long serialVersionUID = 5049729273082639532L;
private List users=new AutoArrayList(UserInfoForm.class); public List getUsers() {
return users;
} public void setUsers(List users) {
this.users = users;
}
}
public class AutoArrayList extends ArrayList{   private static final long serialVersionUID = 7329071318112930773L;
   private Class itemClass;    public AutoArrayList(Class itemClass) {
        this.itemClass = itemClass;
    }    public Object get(int index) {        try {
            while (index >= size()) {
                add( itemClass.newInstance());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.get(index);
    }
}
添加操作的JSP页面
<html:form action="/userInfo">
    用户名1: <html:text property="users[0].username"/><br>
    密 码2: <html:text property="users[0].password"/><br>
    用户名2: <html:text property="users[1].username"/><br>
    密 码2: <html:text property="users[1].password"/><br>
     <html:submit/>
<html:form>在添加操作中的action 的处理将users列表转换为每一个的UserInfoForm再赋给
UserInfo bean中来保存读取操作的JSP页面
 <html:form action="/userInfo">
    <logic:iterate id="user" name="userInfoListForm" property="users">
        <html:text property="username"/><br>
        <html:text property="password"/><br>
    </logic:iterate>
   <html:submit/>
</html:form>想请问下我这样做是否合理,再来怎样来进行修改(初学者).
如果我使用表格来动态的添加或者册除相应的一组UserInfoForm时,
这时修改操作又该如何进行处理

解决方案 »

  1.   

    private String username;
    private String password;
    直接设为数组就可以了 private String[] usernames;
    private String[] passwords;
     用户名1: <html:text property="usernames"/><br>
        密 码2: <html:text property="passwords"/><br>
      

  2.   

    lz代码中的users[0]和users[1]是什么?
      

  3.   

    设为数组可是每次取出来都挺麻烦的,考虑到后来可能有都个属性所以用一个bean 来存取数据
      

  4.   

    对不起下面这个好像用错了,不知怎么用读取操作的JSP页面
     <html:form action="/userInfo">
        <logic:iterate id="user" name="userInfoListForm" property="users">
            <html:text property="username"/><br>
            <html:text property="password"/><br>
        </logic:iterate>
       <html:submit/>
    </html:form>