struts form中用数组接收

cbdhxka 2009-05-13 11:46:55

<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也一样
希望给个例子!
...全文
198 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cbdhxka 2009-05-13
  • 打赏
  • 举报
回复
相似代码!

FORM
cbdhxka 2009-05-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 robyjeffding 的回复:]
可以啊,在你的actionForm中,也定义一个对应的数组属性就可以了,
当你提交表单时,表单数据会自动收集,action调用指定的ActionForm
收集表单,封装数据,前提是actionForm中的属性名要和表单中的控件名一致!
[/Quote]
有代码提供个不.

我想是应该有,只是找不到相似代码
「已注销」 2009-05-13
  • 打赏
  • 举报
回复
<logic:iterate></logic:iterate> 试试行不
robyjeffding 2009-05-13
  • 打赏
  • 举报
回复
可以啊,在你的actionForm中,也定义一个对应的数组属性就可以了,
当你提交表单时,表单数据会自动收集,action调用指定的ActionForm
收集表单,封装数据,前提是actionForm中的属性名要和表单中的控件名一致!
zybzhen 2009-05-13
  • 打赏
  • 举报
回复
如果固定7个,5楼代码可行。
否则,还得是for循环get
yang745306 2009-05-13
  • 打赏
  • 举报
回复
Form中的代码,//我比较喜欢用list,所以用list为例,数组也可以
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("");
}
这还可以改进,你根据所需进行调整吧

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧