本文介绍了数组作为Struts 2中的get参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类似下面的操作
public class CompareAction { private Long[] pids; public Long[] getPids() { return pids; } public void setPids(Long[] pids) { this.pids = pids; } public String displayComparison() { for (Long pid : pids) { System.out.println("pid = " + pid); System.out.println(); } return "success"; } }我正在尝试通过输入以下内容来发送数组地址栏中的网址 http:// localhost:8080 / sm-shop / compare?pids = 12,23,34 。我想要的输出是
I'm trying to send an array by typing following url in the addressbar localhost:8080/sm-shop/compare?pids=12,23,34. The output I want is
pid = 12 pid = 23 pid = 34但我得到的是
pid = 122334我试过google搜索但是找不到怎么做。请帮我弄清楚什么是错的。
I tried googling but couldn't find how to do this. Please help me figure out whats wrong.
推荐答案你需要传递参数 pids 多次:
localhost:8080/sm-shop/compare?pids=12&pids=23&pids=34如果您宣布 pids 属性为数组Struts2会自动将多个参数映射到数组。
If you declared your pids property as array Struts2 will automatically map multiple parameters to array.
更多推荐
数组作为Struts 2中的get参数
发布评论