JAVA 手动分页代码

int pageCount = count / 8 + (count % 8 == 0 ? 0 : 1);//获取总页数   8:每页显示的条数

 

Servlet:

//下一页

int carType=Integer.parseInt(request.getParameter("carType"));
  
  String newscar=request.getParameter("newscar");
  String newscars=new String(newscar.getBytes("ISO-8859-1"), "UTF-8"); 
 
  String sPageNow=request.getParameter("danqianPage");
  int PageNow=Integer.parseInt(sPageNow)*8;
  
  int danqianPage=Integer.parseInt(request.getParameter("danqianPage"))+1; ////当前页
 
  IcarInfo ip=new CarInfoImpl();
  List carInfoList=new ArrayList();
  carInfoList=ip.getAllCarInfo(carType,PageNow,8);
  request.setAttribute("pageCount", request.getParameter("pageCount").trim());
  request.setAttribute("danqianPage", danqianPage);
  

//上一页

int carType=Integer.parseInt(request.getParameter("carType"));
  
  String newscar=request.getParameter("newscar");
  String newscars=new String(newscar.getBytes("ISO-8859-1"), "UTF-8"); 
 
  String sPageNow=request.getParameter("danqianPage");
  int PageNow=(Integer.parseInt(sPageNow)-1)*8;
  
  int danqianPage=Integer.parseInt(request.getParameter("danqianPage"))-1; ////当前页
 
  IcarInfo ip=new CarInfoImpl();
  List carInfoList=new ArrayList();
  carInfoList=ip.getAllCarInfo(carType,PageNow-8,8);
  request.setAttribute("pageCount", request.getParameter("pageCount").trim());
  request.setAttribute("danqianPage", danqianPage);

jsp:

   
  

第${requestScope.danqianPage}页/共${requestScope.pageCount }页

 

 

JS:

function FenyeNext(){
  var pageCount=document.getElementById('pageCounts').value; ///总页数
  var danqianPage=document.getElementById('danqianPages').value; ////当前页
  
  if(parseInt(danqianPage) < parseInt(pageCount)){
   location.href="<%=basePath%>KServlet?action=FenyeNext&PageNow=&{PageNow}&pageCount="+pageCount+"&danqianPage="+danqianPage;
  }else{
   return false;
  }
 }

 function FenyeBack(){
  var pageCount=document.getElementById('pageCounts').value; ///总页数
  var danqianPage=document.getElementById('danqianPages').value; ////当前页
  if(parseInt(danqianPage) > 1){
   location.href="<%=basePath%>KServlet?action=FenyeBack&PageNow=&{PageNow}&pageCount="+pageCount+"&danqianPage="+danqianPage;
  }else{
   return false;
  }
 }

    

留着以后作参数

你可能感兴趣的:(JAVA)