<!--分頁 --> <div style="width: 380px; margin: 0 auto; margin-top: 50px;"> <ul class="pagination" style="text-align: center; margin-top: 10px;"> <!-- 上一頁 --> <!-- 判斷當前頁是否是第一頁 --> <c:if test="${pageBean.currentPage==1 }"> <li class="disabled"><a href="javascript:void(0);" aria-label="Previous"> <span aria-hidden="true">«</span> </a></li> </c:if> <c:if test="${pageBean.currentPage!=1 }"> <li><a href="${pageContext.request.contextPath }/fenYe?currentPage=${pageBean.currentPage-1}&queryName=${queryName}&queryAddress=${queryAddress}&queryDate=${queryDate}&getTag=getMethod" aria-label="Previous"> <span aria-hidden="true">«</span> </a></li> </c:if> <c:forEach begin="1" end="${pageBean.totalPage }" var="page"> <!-- 判斷當前頁 --> <c:if test="${pageBean.currentPage==page }"> <li class="active"><a href="javascript:void(0);">${page}</a></li> </c:if> <c:if test="${pageBean.currentPage!=page }"> <li><a class="test" href="${pageContext.request.contextPath }/fenYe?currentPage=${page}&queryName=${queryName}&queryAddress=${queryAddress}&queryDate=${queryDate}&getTag=getMethod">${page}</a></li> </c:if> </c:forEach> <!-- 判斷當前頁是否是最后一頁 --> <c:if test="${pageBean.currentPage==pageBean.totalPage }"> <li class="disabled"><a href="javascript:void(0);" aria-label="Next"> <span aria-hidden="true">»</span> </a></li> </c:if> <c:if test="${pageBean.currentPage!=pageBean.totalPage }"> <li><a class="test" href="${pageContext.request.contextPath }/fenYe?currentPage=${pageBean.currentPage+1}&queryName=${queryName}&queryAddress=${queryAddress}&queryDate=${queryDate}&getTag=getMethod" aria-label="Next"> <span aria-hidden="true">»</span> </a></li> </c:if> </ul> </div> <!-- 分頁結束 -->
jQuery對其url進行編碼:(參考JS對URL編碼http://www.cnblogs.com/qlqwjy/p/7435054.html)
$(".test").each(function() { var h = $(this).attr("href"); $(this).attr({ href : encodeURI(h) }); });
后台對接收的參數進行解碼:
String getTag = request.getParameter("getTag"); // 組裝查詢條件 Condition condition = new Condition(); // 組裝名稱 String queryName = request.getParameter("queryName"); // 如果是點擊頁號提交方式為get提交進行轉碼 if (getTag != null && !"".equals(getTag.trim())) { queryName = new String(queryName.getBytes("iso-8859-1"), "utf-8"); } if (queryName != null && !"".equals(queryName)) { condition.setQueryName(queryName); // 回顯數據 request.setAttribute("queryName", queryName); }
上面的getTag標志是get方式提交,需要進行解碼,如果為post提交不進行解碼條件。
對提交的英文與數字參數不需要進行解碼。
還有一種方式是:ajax采用post方式提交,請求JSON,然后將JSON填充到表格。
$.ajax({ url:"${baseurl}/fenYe", async:true, type:"POST", date:{"currentPage":1,"queryName":"${queryName}","queryAddress":"${queryAddress}","queryDate":"${queryDate}"}, success: function(data){ }, error:function(){ alert("請求失敗"); }, dataType:"json" });
后台將查詢到的數據轉換為JSON串返回,ajax在成功的回調函數將JSON數據填入表格,關於JSON填充表格參考:
http://www.cnblogs.com/qlqwjy/p/7307514.html