在Struts2.0里面有一个非常强悍的功能就是支持更高级的POJO访问,现在我们就来看看它是如何的神通广大。
要求:获取jsp表单页面的所有数据
1.jsp页面如下:获取多组年月数据
<s:text name="ERMResource.Coverage.Year"/> <s:textfield name="coverage[0].syear" size="3" maxlength="3"/> <s:text name="ERMResource.Coverage.month"/> <s:textfield name="coverage[0].smonth" size="3" maxlength="3"/> <s:textfield name="coverage[1].syear" size="3" maxlength="3"/> <s:text name="ERMResource.Coverage.month"/> <s:textfield name="coverage[1].smonth" size="3" maxlength="3"/> <s:textfield name="coverage[2].syear" size="3" maxlength="3"/> <s:text name="ERMResource.Coverage.month"/> <s:textfield name="coverage[2].smonth" size="3" maxlength="3"/> <s:hidden name="coverage.hidden"/>
2.新增实体类 Coverage.java:
创建一个单独的类,用于装载year、month属性,并提够相应的get、set方法。这里就不贴上代码了。
3.请求处理类:CoverageAction.java:
private List<Coverage> coverage; public List<Coverage> getCoverage() { return coverage; } public void setCoverage(List<Coverage> coverage) { this.coverage = coverage; } public void delEmpty() { for (Coverage c:coverage) { String syear=c.getSyear(); String smonth=c.getSmonth(); system.out.println("year="+syear+"/n"+"month="+smonth); } }