我的Action类中包含CoverageInfoVO类型数组,并希望将值从jsp发送到action类,但它没有被映射。而不是数组如果我切换到ArrayList它工作正常。我的疑问是,我们不能将数组从jsp传递给struts2中的Action吗?我已添加了代码段以便更好地说明。
JSP
<input type="text" name="coverageInfoList[0].month">
动作
public class MyAction {
private CoverageInfoVO[] coverageInfoList;
public CoverageInfoVO[] getCoverageInfoList() {
return coverageInfoList;
}
public void setCoverageInfoList(CoverageInfoVO[] coverageInfoList) {
this.coverageInfoList = coverageInfoList;
}
........
}
CoverageInfoVO
public class CoverageInfoVO {
private String month;
private String enrollmentPremium;
private String secondLowestCostSilverPlanPremium;
private String advancePaymentOfPremiumTaxCredit;
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
...................
}
答案 0 :(得分:1)
最后,我能够找出jsp值未映射到Object Array背后的原因。原因是CoverageInfoVO没有自动在数组内部初始化,因此需要在构造函数内手动初始化,然后自动映射值。
<强>实施例强>
public MyAction(){
this.coverageInfoList = new CoverageInfoVO[13];
for (int i = 0; i < coverageInfoList.length; i++)
this.coverageInfoList[i] = new CoverageInfoVO();
}