在ActionForm中定義一個類型爲HashMap的類變量
public Object getInvestimatesubMap(String key) ...{
return investimatesubMap.get(key);
}
public void setInvestimatesubMap(String key, Object value) ...{
this.investimatesubMap.put(key, value);
}
private Collection listInvestimatesub;
public void resetListInvestimatesub() {
Collection myInvestimatesub = new ArrayList();
Collection myKeys = investimatesubMap.keySet();
for (Iterator it = myKeys.iterator(); it.hasNext();) {
String key = (String) it.next();
String getKey = this.investimatesubMap.get(key).toString();
String[] properties = key.split("_");
String property = properties[0];
String vol = properties[1];
String id = properties[2];
InvestimatesubForm investimatesubForm = new InvestimatesubForm();
investimatesubForm.setEttprojid(this.ettprojid);
investimatesubForm.setVoltagegrade(vol);
investimatesubForm.setInvestestimateid(id);
investimatesubForm.setTranssubstninvest(getKey);
myInvestimatesub.add(investimatesubForm);
}
this.listInvestimatesub = myInvestimatesub;
}
public Collection getListInvestimatesub() {
if (this.listInvestimatesub == null) {
resetListInvestimatesub();
}
return listInvestimatesub;
}
public void setListInvestimatesub(Collection listInvestimatesub) {
this.listInvestimatesub = listInvestimatesub;
}
注意:變量一定要實例化,get方法的返回值一定是Object,set方法的value類型也一定是Object。
在進入jsp之前的Action中
String key = "lineinvest_" + vol + "_" + id
investimatemainForm.setInvestimatesubMap("key", "testValue");
jsp中
可以用key值傳遞一些跟當前所填寫的字段相關的信息,再在後臺解析