数组作为Struts 2中的get参数 [英] Array as get parameter in Struts 2

查看:103
本文介绍了数组作为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 http://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 多次:

http://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参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆