<tr>
<td class="x2" background="images/bg.gif">
预计
</td>
<td class="x2">
<html:text property="plan1" size="9"></html:text>
</td>
<td class="x2">
<html:text property="plan2" size="9"></html:text>
</td>
<td class="x2">
<html:text property="plan3" size="9"></html:text>
</td>
<td class="x2">
<html:text property="plan4" size="9"></html:text>
</td>
<td class="x2">
<html:text property="plan5" size="9"></html:text>
</td>
<td class="x2">
<html:text property="plan6" size="9"></html:text>
</td>
<td class="x2">
<html:text property="plan7" size="9"></html:text>
</td>
</tr> <tr>
<td class="x2" background="images/bg.gif">
实际
</td>
<td class="x2">
<html:text property="fact1" size="9"></html:text>
</td>
<td class="x2">
<html:text property="fact2" size="9"></html:text>
</td>
<td class="x2">
<html:text property="fact3" size="9"></html:text>
</td>
<td class="x2">
<html:text property="fact4" size="9"></html:text>
</td>
<td class="x2">
<html:text property="fact5" size="9"></html:text>
</td>
<td class="x2">
<html:text property="fact6" size="9"></html:text>
</td>
<td class="x2">
<html:text property="fact7" size="9"></html:text>
</td>
</tr>
可不可以在Form中定义一个数组来接收<html:text>plan1-7 的数据,以便后台遍历,而不一个一个GET.fact1-7也一样
希望给个例子!
当你提交表单时,表单数据会自动收集,action调用指定的ActionForm
收集表单,封装数据,前提是actionForm中的属性名要和表单中的控件名一致!
private List<String> list = new ArrayList<String>list;
//在form 中定义一个List<String>list;生成相应的get、set方法。
private void setList(){
this.list.add(this.plan1);
this.list.add(this.plan2);
this.list.add(this.plan3);
setList(list);//调用的上面生成的set方法,给list赋值
}
Action中的代码
public ActionForward get(ActionMapping , Form , HttpServletRequest , HttpServletResponse )
{
form.setList(); //调用form中的方法得到值
System.out.println(form.getList());//可以看到form.getList()中已经是页面中传过来的值
return mapping.findForward("");
}
这还可以改进,你根据所需进行调整吧
否则,还得是for循环get