关闭

js提交from表单 多参数

9122人阅读 评论(0) 收藏 举报

做翻页功能处理

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 参数能正常接收。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:223327次
    • 积分:2426
    • 等级:
    • 排名:第15785名
    • 原创:43篇
    • 转载:53篇
    • 译文:0篇
    • 评论:17条
    最新评论
    阻止网站镜像技术