Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an action like below

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";
    }
}

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

But what I'm getting is

pid = 122334

I tried googling but couldn't find how to do this. Please help me figure out whats wrong.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
638 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to pass parameter pids multiple times:

http://localhost:8080/sm-shop/compare?pids=12&pids=23&pids=34

If you declared your pids property as array Struts2 will automatically map multiple parameters to array.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...