Jsp Spring MVC使用查询参数返回同一页面?
我有一个针对SpringMVC3.x的index.jsp,其中包含一个下拉列表框 返回到同一页面的最简单方法是什么,但对列表中的选定项使用查询参数 myPage/index.jspJsp Spring MVC使用查询参数返回同一页面?,jsp,spring-mvc,jsp-tags,query-parameters,Jsp,Spring Mvc,Jsp Tags,Query Parameters,我有一个针对SpringMVC3.x的index.jsp,其中包含一个下拉列表框 返回到同一页面的最简单方法是什么,但对列表中的选定项使用查询参数 myPage/index.jsp(http://localhost:8085/mypage) 尝试返回“重定向:索引”项=“+selectList尝试使用ajax提交表单 var str=$(“#myForm”).serialize() $.ajax({ 类型:“post”, 数据:str, url:“indexSubmit”, async:fals
(http://localhost:8085/mypage)
尝试返回“重定向:索引”项=“+selectList代码>尝试使用ajax提交表单 var str=$(“#myForm”).serialize() $.ajax({ 类型:“post”, 数据:str, url:“indexSubmit”, async:false, 数据类型:“json”, 成功:函数(){ 警惕(“成功”); }
}); 我确实找到了一些有效的方法,但不确定是否是最佳实践。字符串referer=request.getHeader(“referer”);返回“重定向:+referer;。。。。更少的查询参数…但至少它会重定向回原始页面。好吧,这样就行了…您的解决方案行了。然而,这是处理这个案件的最好/最简单的方法吗…一篇回到同一页的文章?这取决于,顺便问一下,在你的案件中有什么问题吗?
<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>
@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.
}