0

这是 index.jsp 页面:

<form method="post">
    <select name="channel">
        <option>Star Movie</option>
        <option>HBO</option>
        ...
        //More television channel option
    </select>
    <select name="channel">
        <option>Star Movie</option>
        <option>HBO</option>
        ...
        //More television channel option
    </select>
    ...
    //More select input added dynamic by user
    <button class="btn-add" >Add channel</button>
    <input type="submit" value="Submit"/>
</form>

这是我的控制器

@RequestMapping(value = "/channelReview", method = RequestMethod.POST)
ModelAndView actionChannelReview(@RequestParam("channel") String[] channelLst){
    ...
    //Do something else
}

这里的问题是为什么 channelLst 只有 1 个元素并且它总是表单上的最后一个值,无论有多少用户在表单上添加。

4

2 回答 2

1
 <form method="post">
        <select name="channel">
            <option value="1">Star Movie</option>
            <option value="2">HBO</option>
            ...
            //More television channel option
        </select>
        <select name="channel">
            <option value="3">Star Movie</option>
            <option value="4">HBO</option>
            ...
            //More television channel option
        </select>
        ...
        //More select input added dynamic by user
        <button class="btn-add" >Add channel</button>
        <input type="submit" value="Submit"/>
    </form>

现在你会得到值...... vale 属性不是你给的

于 2014-06-11T05:21:32.003 回答
1

我没有遇到任何问题,我使用了您提到的相同代码,我在 channelLst 中有 2 个频道在此处输入图像描述

我还添加了动态下拉菜单,可以很好地处理任意数量的下拉菜单

于 2014-06-10T21:47:49.293 回答