Struts ActionForm用Map回封装数据

Struts ActionForm用Map来封装数据
1。当表单中数据会增加的时候,在form中写每一个属性不利于软件的升级和维护,这个时候我们有两种解决方案,一种是采用DynaActionForm,另一种就是采用Map属性,
下面是示例代码:
Java代码
package com.mj.forms;  
 
import java.util.HashMap;  
import java.util.Map;  
 
import org.apache.struts.action.ActionForm;  
 
/** 
*  
* @author M.J 

*/ 
public class FormMapTest extends ActionForm{  
    private Map map=new HashMap();  
    private int testInt;  
      
    public Map getMap() {  
        return map;  
    }  
 
    public void setMap(Map map) {  
        this.map = map;  
    }  
 
    public int getTestInt() {  
        return testInt;  
    }  
 
    public void setTestInt(int testInt) {  
        this.testInt = testInt;  
    }  
 
    /** 
     *  
     * @param key 
     * @return 
     */ 
    public Object getValue(String key){  
        return map.get(key);  
    }  
      
    /** 
     *  
     * @param key 
     * @param value 
     */ 
    public void setValue(String key, Object value){  
        map.put(key, value);  
    }  


package com.mj.forms;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts.action.ActionForm;

/**
*
* @author M.J
*
*/
public class FormMapTest extends ActionForm{
private Map map=new HashMap();
private int testInt;

public Map getMap() {
return map;
}

public void setMap(Map map) {
this.map = map;
}

public int getTestInt() {
return testInt;
}

public void setTestInt(int testInt) {
this.testInt = testInt;
}

/**
*
* @param key
* @return
*/
public Object getValue(String key){
return map.get(key);
}

/**
*
* @param key
* @param value
*/
public void setValue(String key, Object value){
map.put(key, value);
}
}


jsp业面要稍微作以下修改:
Html代码
<html:text property="value(userId)"/> 
<html:password property="value(password)"/>