数组作为Struts 2中的get参数

编程入门 行业动态 更新时间:2024-10-27 04:28:22
本文介绍了数组作为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参数

本文发布于:2023-10-29 13:21:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539802.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   参数   Struts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!