请教:struts中Action取多值问题?

liuboccut 2008-07-30 11:12:32
id name
1 name1
2 name2
在struts中,form页面一次提交上述两个值,再
ShenPiForm ShenPiForm = (ShenPiForm) form;
int id = ShenPiForm.getId();
结果只能得到 id=1的值,如何将两个或多个值同时取到,谢谢
...全文
168 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
grandyhwang 2008-08-04
  • 打赏
  • 举报
回复
你可以在ShenPiForm 类中创建一个对象数组作为它的一个属性,假如你的对象叫item ,此对象包含两个字段:id,name

具体写法:
private XXX[] items; -------XXX是item的类型
加上get/set方法

最后在action中直接调用ShenPiForm.getItems(),所有东西就全可以取到了。

注意在页面上将标签的name属性的值由原来的id改为items.id

试试
youjianbo_han_87 2008-08-04
  • 打赏
  • 举报
回复
唉,都说的这么明白了,楼主还是去看看最基本的东西,学好了再说吧
zou_wei_forever 2008-08-04
  • 打赏
  • 举报
回复
在ActionForm中可以设一个数组:String [] args;
在jsp页面中:

<html:form>
<html:text property="args[0]"/>
<html:text property="args[1]"/>
<html:submit/>
</html:form>
liuboccut 2008-07-30
  • 打赏
  • 举报
回复
这样的结果参数类型是String[]类型,如何将其转化为int[]?
youjianbo_han_87 2008-07-30
  • 打赏
  • 举报
回复
在循环打印记录的标签里面
加<input type="hidden" name="idArray" value="<bean:write property="id" name="*Form"/>"/>
到Action里面取,这个idArray里面就是你要的,如果不是循环动态打印出來的,那在JS里面提交前给Form里面这idArray赋值,然后在提交
dryZeng 2008-07-30
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jyq0105 的回复:]
String ids[]=request.getParameterValues("name");
[/Quote]
jyq0105 2008-07-30
  • 打赏
  • 举报
回复
String ids[]=request.getParameterValues("name");
365810247 2008-07-30
  • 打赏
  • 举报
回复
用List 或者 Map吧
xiaoxiao321 2008-07-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 liuboccut 的回复:]
String ids[]=request.getParameterValues("Id");
int item[] = new int[ids.length];
for(int i=0;i <items.lengh;i++){
item[i]=Integer.parseInt(ids[i]);
}
[/Quote]
试一下这个
liuboccut 2008-07-30
  • 打赏
  • 举报
回复
String ids[]=request.getParameterValues("Id");
int item[] = new int[ids.length];
for(int i=0;i <items.lengh;i++){
item[i]=Integer.parseInt(ids[i]);
}
liuboccut 2008-07-30
  • 打赏
  • 举报
回复
String ids[]=request.getParameterValues("Id");
int item[];
for(int i=0;i<items.lengh;i++){
item[i]=Integer.parseInt(item[i]);
}

67,537

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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