永发信息网

求jsp分页代码

答案:3  悬赏:10  手机版
解决时间 2021-07-18 19:27
  • 提问者网友:心如荒岛囚我终老
  • 2021-07-18 05:22
用jsp实现分页效果要求如下:当我点击数字连接10的时候会动态加载后面的连接而前面的1到4的连接自带隐藏,用jsp代码怎么实现。
最佳答案
  • 五星知识达人网友:掌灯师
  • 2021-07-18 06:32

<body>
<center><h3>所有的用户信息</h3></CENTER>
<table align="center" border="1" cellspacing="0" bordercolor="red">
<tr>
<th>
用户Id
</th>
<th>
用户名
</th>
<th>
用户密码
</th>
<th>
用户性别
</th>
<th>
用户住址
</th>
<th>
真实姓名
</th>
<th>
用户年龄
</th>
</tr>


<c:forEach var="u" items="${userlist}">
<tr>
<td>
${u.userid }
</td>
<td>
${u.username }
</td>
<td>
${u.password }
</td>
<td>
${u.sex }
</td>
<td>
${u.age }
</td>
<td>
${u.address }
</td>
<td>
${u.realname}
</td>
</tr>


</c:forEach>
</table>
<center>

<a href="/pageturn/pageturn.do?current=1">首页</a>
<c:forEach var="value" begin="1" end="${endpage}">
<a href="/pageturn/pageturn.do?current=${value}">${value}</a>
</c:forEach>
<c:choose>
<c:when test="${current eq 1}">
<a href="/pageturn/pageturn.do?current=${current+1}">下一页</a>
</c:when>
<c:when test="${current eq endpage}">
<a href="/pageturn/pageturn.do?current=${current-1}">上一页</a>
</c:when>
<c:otherwise>
<a href="/pageturn/pageturn.do?current=${current-1}">上一页</a>
<a href="/pageturn/pageturn.do?current=${current+1}">下一页</a>
</c:otherwise>
</c:choose>
<a href="/pageturn/pageturn.do?current=${endpage}">末页</a>
<select onchange="javascript:location.href='/pageturn/pageturn.do?current='+this.value">
<c:forEach var="index" begin="1" end="${endpage}">
<c:choose>
<c:when test="${current eq index}">
<option value="${index}" selected="selected">${index}</option>
</c:when>
<c:otherwise>
<option value="${index}">${index}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
</center>
</body>
</html>

全部回答
  • 1楼网友:春色三分
  • 2021-07-18 08:10

把内容稍改一下就可以了

<%-- Document : checkDB Created on : 2009-11-1, 23:21:46 Author : Administrator --%>

<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="java.sql.*" %> <%@page import="java.util.*" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd"> <% int dipage = 1; String pages = request.getParameter("dipage"); if (pages == null) { pages = "1"; } try { dipage = Integer.parseInt(pages); } catch (Exception e) { dipage = 1; } %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <% request.setCharacterEncoding("UTF-8");

try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=ming", "min", "123");

Statement stmt = con.createStatement(); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery("select * from liuyan order by time desc"); int countRecord = 0; int i = 0; int countPageRecord = 0; int countPage = 1; countPageRecord = 5; rs.last(); countRecord = rs.getRow(); if (countRecord / countPageRecord == 0) { countPage = countRecord / countPageRecord; } else { countPage = countRecord / countPageRecord + 1; } if ((dipage - 1) * countPageRecord == 0) { rs.beforeFirst(); } else { rs.absolute((dipage - 1) * countPageRecord); }

%> <% while (rs.next()) {%> <p> <table border="0">

<tbody> <tr> <td><img src="d:\我的文档\桌面\tian\image\9809.jpg"/> </td> <td > &nbsp; &nbsp; &nbsp;</td> <td>主题:<%=rs.getString(4)%></td> </tr> <tr>

<td>姓名:<%=rs.getString(2)%></td> <td > &nbsp; &nbsp; &nbsp;</td> <td > 内容:</td> </tr> <tr> <td>E-mail:<%=rs.getString(3)%></td> <td > &nbsp; &nbsp; &nbsp;</td> <td width="150"><%=rs.getString(5)%></td> </tr> </tbody> </table></p> -------------------------------------------------------- <% i++; if (i >= countPageRecord) { break; } } out.print("共" + countRecord + "条记录,共" + countPage + "页,当前第" + dipage + "页,每页" + countPageRecord + "条记录"); if (dipage == 1); else { out.print("<a href=showly.jsp?dipage=1>首页</a>,"); out.print("<a href=showly.jsp?dipage=" + (dipage - 1) + ">上一页</a>,"); } if (dipage == countPage) { ; } else { out.print("<a href=showly.jsp?dipage=" + (dipage + 1) + ">下一页</a>,"); out.print("<a href=showly.jsp?dipage=" + countPage + ">末页</a>");

} out.print("<tr>");

rs.close(); stmt.close(); con.close(); } catch (Exception e) { out.println("数据库异常"); } %> <form name="liuyanban" action="mas_saves.jsp" method="POST"> <table border="0">

<tbody> <tr> <td>留言人:</td> <td><input type="text" name="lname" value="" /></td> </tr> <tr> <td>E-mail:</td> <td><input type="text" name="Email" value="" /></td> </tr> <tr> <td>留言主题:</td> <td><input type="text" name="zhuti" value="" /></td> </tr> <tr> <td>留言信息:</td> <td></td> </tr>

</tbody> </table> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea name="neirong" rows="5" cols="35"> </textarea> <table border="0">

<tbody> <tr> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="提交" name="tijiao" /></td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="关闭" name="close" /></td> </tr> </tbody> </table> </form> <% out.print("<form action=check.jsp method=post>"); out.print("<input type=submit value=返回></form>");%> </body> </html>

  • 2楼网友:迟山
  • 2021-07-18 06:38

我给你提一下思路吧。首先分页你会不会,如果不会的话下面的就不麻烦你看了

如果你分页代码写好了后你就可以用变量获得总信息条数/你设置的每页显示的信息条数,然后

你可以获得总页数的变量值。至于你后面的提出的要求就是js实现了。你实现了分页就可以获取当前第几页

然后在获取的处调用js代码实现应该可以了,

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯