新人求助,java web实现分页为什么编译不成功啊?

qq_22015225 2015-11-21 11:34:52
An error occurred at line: 69 in the jsp file: /split_page_plugin/emp_list_true.jsp
URL cannot be resolved to a variable
mysql我已经建好表啦,应该不关数据库的事啊
<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>
<html>
<head><title>www.mldnjava.cn,MLDN高端Java培训</title>
<style type="text/css">
<!--
.STYLE6 {font-size: 12px}
.STYLE10 {font-size: 14px; font-weight: bold; }
-->
</style>
</head>
<script language="javascript">
function changeColor(obj,color){
obj.bgColor = color ;
}
</script>
<body>
<%!
public static final String URL = "emp_list_true.jsp" ;
%>
<%!
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
public static final String DBURL = "jdbc:mysql://localhost:3306/mldn" ;
public static final String DBUSER = "root" ;
public static final String DBPASSWORD = "123456" ;
%>
<%
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,10,15,20,25,30,50,100} ;
%>
<%
try{
currentPage = Integer.parseInt(request.getParameter("cp")) ;
} catch(Exception e) {}
try{
lineSize = Integer.parseInt(request.getParameter("ls")) ;
} catch(Exception e) {}
%>
<%
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
String sql = "SELECT COUNT(empno) FROM emp" ;
pstmt = conn.prepareStatement(sql) ;
rs = pstmt.executeQuery() ;
if(rs.next()){ // 取得全部的记录数
allRecorders = rs.getInt(1) ;
}
%>
<center>
<h1>雇员列表</h1>
<script language="javascript">
function go(num){
document.getElementById("cp").value = num ;
document.spform.submit() ; // 表单提交
}
</script>
<%
pageSize = (allRecorders + lineSize -1) / lineSize ;
%>
<%
sql = "SELECT * FROM ( " +
" SELECT empno,ename,job,hiredate,sal,comm,ROWNUM rn " +
" FROM emp WHERE ROWNUM<=? ORDER BY empno) temp " +
" WHERE temp.rn>? " ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setInt(1,currentPage * lineSize) ;
pstmt.setInt(2,(currentPage-1) * lineSize) ;
rs = pstmt.executeQuery() ;
%>
<form name="spform" action="<%=URL%>" method="post">
<input type="button" value="首页" onclick="go(1)" <%=currentPage==1?"DISABLED":""%>>
<input type="button" value="上一页" onclick="go(<%=currentPage-1%>)" <%=currentPage==1?"DISABLED":""%>>
<input type="button" value="下一页" onclick="go(<%=currentPage+1%>)" <%=currentPage==pageSize?"DISABLED":""%>>
<input type="button" value="尾页" onclick="go(<%=pageSize%>)" <%=currentPage==pageSize?"DISABLED":""%>>
跳转到第<select name="selcp" onchange="go(this.value)">
<%
for(int x=1;x<=pageSize;x++){
%>
<option value="<%=x%>" <%=x==currentPage?"SELECTED":""%>><%=x%></option>
<%
}
%>
</select>页
每页显示
<select name="ls" onchange="go(1)">
<%
for(int x=0;x<lsData.length;x++){
%>
<option value="<%=lsData[x]%>" <%=lsData[x]==lineSize?"SELECTED":""%>><%=lsData[x]%></option>
<%
}
%>
</select>

<input type="hidden" name="cp" value="1">
</form>
<TABLE BORDER="1" cellpadding="5" cellspacing="0" bgcolor="F2F2F2" width="100%">
<TR onMouseOver="changeColor(this,'white')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle"><span class="STYLE10">编号</span></td>
<td align="center" valign="middle"><span class="STYLE10">姓名</span></td>
<td align="center" valign="middle"><span class="STYLE10">职位</span></td>
<td align="center" valign="middle"><span class="STYLE10">雇佣日期</span></td>
<td align="center" valign="middle"><span class="STYLE10">工资</span></td>
<td align="center" valign="middle"><span class="STYLE10">奖金</span></td>
</TR>
<%
while(rs.next()){
int empno = rs.getInt(1) ;
Varchar ename = rs.getVarchar(2) ;
Varchar job = rs.getVarchar(3) ;
Date hiredate = rs.getDate(4) ;
float sal = rs.getFloat(5) ;
float comm = rs.getFloat(6) ;
%>
<TR onMouseOver="changeColor(this,'white')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle"><span class="STYLE6"><%=empno%></span></td>
<td align="center" valign="middle"><span class="STYLE6"><%=ename%></span></td>
<td align="center" valign="middle"><span class="STYLE6"><%=job%></span></td>
<td align="center" valign="middle"><span class="STYLE6"><%=hiredate%></span></td>
<td align="center" valign="middle"><span class="STYLE6"><%=sal%></span></td>
<td align="center" valign="middle"><span class="STYLE6"><%=comm%></span></td>
</TR>
<%
}
%>
</table>
<%
conn.close() ;
%>
</center>
</body>
</html>
...全文
93 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sinat_31535993 2015-11-23
DBDRIVER = "org.gjt.mm.mysql.Driver" ;这是什么鬼?mysql驱动是这么写的? 这个SQL又是什么鬼?mysql分页的关键词是limit,这个明显是oracle的写法
回复
sql = "SELECT * FROM ( " + " SELECT empno,ename,job,hiredate,sal,comm,ROWNUM rn " + " FROM emp WHERE ROWNUM<=? ORDER BY empno) temp " + " WHERE temp.rn>? " ; 你这个sql,能运行吗?WHERE temp.rn>? 这条件是个什么鬼?
回复
I_am_a_Beginner 2015-11-22
同意上楼的看法!
回复
海会圣贤 2015-11-22
这种方式好乱啊,强烈建议楼主至少要用JavaBean + Servlet + JSP的方式来实现吧。
回复
问题是什么?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-11-21 11:34
社区公告
暂无公告