0

我每个 spring mvc 3.x 都有一个 index.jsp,其中包含一个下拉列表框。

什么是最简单的回发到同一页面但每个列表中选定项目的查询参数的方法?

myPage/index.jsp(http://localhost:8085/mypage)

   <form class="form-horizontal" action="myController/indexSubmit" method="post">
        <select name="selectList" class="form-control" placeholder=".input-medium" height>
            <c:forEach items="${theList}" var="item" varStatus="count"> 
                <option value="${count.index}">${item }</option>
            </c:forEach>
        </select>   
        <button type="submit" class="btn btn-primary btn-medium">Submit</button>   
    </form>

->http://localhost:8085/GameAnalytics?selectedItem=3

我尝试使用回发重定向回 /index 似乎不起作用。

@RequestMapping(value="indexSubmit", method = RequestMethod.POST)
public String indexSubmit( @RequestParam String selectList, ModelMap model) {
    System.out.println("Selected Title: " + selectList);
    return "forward:/index?item=" + selectList;  // add query params and redirect back to main index page.
}   
4

2 回答 2

2

尝试return "redirect:index?item=" + selectList;

于 2013-08-28T05:28:30.210 回答
0

尝试 ajax 提交表单。

var str = $("#myForm").serialize();

$.ajax({ type:"post", data:str, url:"indexSubmit", async: false, dataType: "json", success: function(){ alert("success"); } });

于 2013-08-28T10:48:54.927 回答