首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring发布回同一个页面与查询参数?

Spring发布回同一个页面与查询参数?
EN

Stack Overflow用户
提问于 2013-08-28 04:42:21
回答 2查看 2.5K关注 0票数 0

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

什么是最简单的方式回发到相同的页面,但查询对每个选定的项目在列表中?

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

代码语言:javascript
复制
   <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,但似乎不起作用。

代码语言:javascript
复制
@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.
}   
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-28 05:28:30

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

票数 2
EN

Stack Overflow用户

发布于 2013-08-28 10:48:54

尝试ajax进行表单提交。

var str =$(“#myForm”).serialize()

$.ajax({ type:"post",data:str,url:"indexSubmit",异步: false,dataType:"json",dataType: function(){警告(“成功”);});

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18479606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档