javaweb 用户可以自由选择出现的行列数(每页要显示多少);

图片说明

我输入自己想要的行列数,比如5行,他会变成5行,但是如果再点下面的页码就又变成原来的显示行数

<%@ page contentType="text/html;charset=UTF-8"%>
<%response.setHeader("Pragma","No-cache"); %>
<%response.setHeader("Cache-Control","no-cache"); %>
<%response.setHeader("Expires","0");%>
<%@ page import="cn.jbit.pagination.dao.PageDao" %>
<%@ page import="cn.jbit.pagination.bean.Topic" %>
<%@ page import="java.util.List" %>
<%

    String pageNumber = request.getParameter("pageNumber"); //显示第几页
    String getNumber=request.getParameter("inp");
    if(getNumber== null ||getNumber.equals("")){
        getNumber="4";
    }
    if(pageNumber == null || pageNumber.equals("")){ //如果没有此参数为空

        pageNumber = "1"; //缺省显示第一页

    }
    int number = Integer.parseInt(pageNumber); //转成整数类型
    int RECORD_COUNT = Integer.parseInt(getNumber); //每页显示的数据条数

    int start = 0; //从第几条开始

    int end = 0; //到第几条结束
    start = (number - 1) * RECORD_COUNT;
    end = number * RECORD_COUNT;
    System.out.println("start:"+start);
    System.out.println("end:"+end);
    PageDao dao = new PageDao();
    List<Topic> topics = dao.list(start,end);
    int count = dao.totalCount(); //总条数

    int total = (count - (count%RECORD_COUNT))/RECORD_COUNT; //总页数

    if(count % RECORD_COUNT != 0){
        total++;
    }
    System.out.println("++"+getNumber);
    System.out.println("++RECORD_COUNT"+RECORD_COUNT);

 %>
<html>
<head>
<script language='Javascript'>
    function selectShow(){
    var getnumber=document.getElementById("select");
    var getvalue=document.getElementById("select").value;
    document.location='index.jsp?pageNumber='+getvalue+'&getNumber=<%= getNumber%>';
}
    function load()
    {
        var getnumber=document.getElementById("select");
        getnumber.selectedIndex = <%=pageNumber%> - 1;  //下拉菜单的索引号
    }
    function on(){
        var getvalue=document.getElementById("input").value;
        alert(getvalue)
        document.location='index.jsp?pageNumber=1&getNumber='+getvalue;

    }

</script>
<title>航班查询</title>
</head>
<style>
 a{text-decoration:none;}
</style>
<body onload="load()">
<br/>

<center>
自定义你要显示的行数:<br/>
<form action="index.jsp?pageNumber=1&getNumber=<%=getNumber%>" method="post"><br/>
<input name="inp" id="input" value="<%= RECORD_COUNT%>"/>
<input type="submit" value="onclick" name="but" onclick="on()"/>
  </form>
<table width='40%'  >
<tr bgcolor='pink'>
<td width='30%'  >专题编号</td>
<td width='50%'>专题名称</td>
</tr>
<%for(int i = 0;i < topics.size();i++){ %>
<tr>
<td width='30%'><%=topics.get(i).getTid() %></td>
<td width='50%'><%=topics.get(i).getTname() %></td>
</tr>
<%} %>
</table>
<br/>
<br/>
页码:
<a href="index.jsp?pageNumber=1&getNumber=<%=getNumber%>" >&nbsp;&nbsp;首页</a>&nbsp;&nbsp;&nbsp;
<%for(int i = 1;i <= total;i++) {%>
<a href="index.jsp?pageNumber=<%=i%>&getNumber=<%=getNumber%>"><%=i%></a>&nbsp;&nbsp;&nbsp;
<%}%>
<a href="index.jsp?pageNumber=<%=total%>&getNumber=<%=getNumber%>">末页</a>
<select id="select" onchange="selectShow()">
<%for(int i = 1;i <= total;i++) {%>
 <option value="<%=i%>" ><%=i%></option>

<%}%>
</select>
</center>
</body>
</html>

2个回答

每次点击下一页的时候,将设置的条数回传给服务器端,

将设置的条数传给服务器端

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐