李锋的博客

软件实施

js提交from表单 多参数

做翻页功能处理

1、 jsp 翻页

<form name="form" action="" METHOD="post">
<input type="button" value="首页"  onclick="filter()" />
<input type="button" value="上一页" onclick="firstfilter()" /> 
<input type="button"  value="下一页"  onclick="lastfilter()" />
<input type="button" value="末页" onclick="maxfilter()" />
<!-- <input type="hidden" name="resType" id="resType" value="<%=resType%>"/> -->

  </form>


2、js函数提交from表单

  <script  type="text/javascript">
function filter(){
   var url = "<%=basePath%>home/reading_book?currentpage=1&resType=<%=resType%>";
 document.form.action = url;   
   document.form.method = "post";   
   document.form.submit(); 

}
function firstfilter(){
var url ="<%=basePath%>home/reading_book?currentpage=<%=lastpage%>&resType=<%=resType%>";
document.form.action = url;   
document.form.method = "post";   
document.form.submit()
}
function lastfilter(){
  var url = "<%=basePath%>home/reading_book?currentpage=<%=nextpage%>&resType=<%=resType%>";
document.form.action = url;  
document.form.method = "post";    
document.form.submit(); 
}
function maxfilter(){
var url = "<%=basePath%>home/reading_book?currentpage=<%=max%>&resType=<%=resType%>";
 
document.form.action = url;   
document.form.method = "post";   
document.form.submit()
}
</script>


3、后台处理          如果改为get提交  下面的 resType  获取的值为NULL

 
@RequestMapping(value = "/home/reading_book", method = RequestMethod.POST)
public ModelAndView reading_bookPOST(HttpServletRequest request,
HttpServletResponse response, ModelMap modelMap) throws Exception {
      VUser user = (VUser) request.getSession().getAttribute("User");            
    i nt resType = Integer.parseInt(request.getParameter("resType"));

   int page = 1;
if (!(("").equals(request.getParameter("currentpage")))
&& !(request.getParameter("currentpage") == null)) {
page = Integer.parseInt(request.getParameter("currentpage"));
}
List data = booksheet.fetchAllSheet(-1, -1, "0", user.getU_OId(),
resType);


modelMap.put("booklist", booksheet.fetchAllSheet((page - 1) * 6, 6,
"0", user.getU_OId(), resType));
modelMap.put("currentpage", page);
modelMap.put("resType", resType);
modelMap.put("max", data.size() % 6 == 0 ? data.size() / 6 : data
.size() / 6 + 1);
return new ModelAndView("/home/reading_book", modelMap);
}


在测试的过程中,如果改为get提交,服务端接受不到提交的参数,改为Post 参数能正常接收。

阅读更多
上一篇SpringMVC+AJAX
下一篇微信开发技术
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭