Ma_Smile 2017-05-17 06:39 采纳率: 0%
浏览 3985

JSP真分页问题,点击下一页没有反应

点击下一页之后没有任何反应。。。而且跳转到某一页功能也不能实现
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>

My JSP 'emp_list.jsp' starting page


<%!
public static final String URL = "emp_list.jsp";
public static final String DBDRIVER = "com.mysql.jdbc.Driver";
public static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
public static final String DBUSER = "root";
public static final String DBPASS = "root";
%>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
%>
<%
int currentPage = 1; //当前所在页,默认为1
int lineSize = 3; //每次显示的记录数
int allRecorders = 0; //表示全部的记录
int pageSize = 1; //表示全部的页数(尾页)
int [] lsData = {1,3,5,7,9};
%>
<%
try {
String cPage = request.getParameter("cp");
if (cPage==null){
cPage="1";
}
String lSize = request.getParameter("ls");
if (lSize==null){
lSize = "3";
}
currentPage = Integer.parseInt(cPage);
lineSize = Integer.parseInt(lSize);
}catch(Exception e){
System.out.println("错误1");
}
%>
<%

try {
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String sql = "select COUNT(empno) from emp";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()){
allRecorders = rs.getInt(1);
}
//System.out.println(allRecorders);
pageSize = (allRecorders + lineSize -1) / lineSize;
//System.out.println(pageSize);
}catch(Exception e){
System.out.println("错误2");
}
%>
<br> function go(num){<br> document.getElementById(&quot;cp&quot;).value = num;<br> document.spform.submit();<br> }<br>

雇员列表


>

<%
for (int x=1; x<=pageSize; x++){
%>

<%
for (int x=0; x %>










<%
try {
String sql2 = "select * from emp limit "+ (currentPage - 1) * lineSize + "," + currentPage * lineSize;
pstmt = conn.prepareStatement(sql2);
rs = pstmt.executeQuery();
while(rs.next()){
int no = rs.getInt(1);
String name = rs.getString(2);
String job = rs.getString(3);
Date date = rs.getDate(4);
float sal = rs.getFloat(5);
%>








<%
}
}catch(Exception e){
System.out.println("错误3");
}finally{
try{
rs.close();
pstmt.close();
conn.close();
}catch(Exception e){
System.out.println("错误4");
}
}
%>
编号 姓名 工作 日期 工资
<%=no %> <%=name %> <%=job %> <%=date %> <%=sal %>


  • 写回答

2条回答 默认 最新

  • 广州-张瑞宝 2017-05-17 08:52
    关注

    楼主:点击‘下一页’服务器请求执行了吗?或者js执行了吗?
    然后 检查 查询的开始位置是不是超出了总的数据数量(当前查询没有数据?)?

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?