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

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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)