关于jsp分页问题

dearkp 2006-09-22 04:02:23
这是我写的网业代码,从数据库提取数据并实现分页功能,但是系统提示出错,请大家帮忙,找了好多台秒年 实在不知道错误在哪,代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.lang.Integer"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
response.setContentType("text/html; charset=gb2312");
request.setCharacterEncoding("gb2312");
%>
<title>无标题文档</title>
<style type="text/css">
<!--
body {
margin-top: 0px;
}
-->
</style>
<link href="css.css" rel="stylesheet" type="text/css">
<SCRIPT src="images/rainbow.js"></SCRIPT>
</head>
<%
int maxperpage=15;
int totalput;
int currentpage;
int totalpage;
int i,j;
String page1=request.getParameter("page");
if(request.getParameter("page")!=null)
{currentpage=Integer.parseInt(request.getParameter("page"));}
else
currentpage=1;
String sql;
ResultSet rs;
%>
<body>

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><%@ include file="top.jsp"%></td>
</tr>
<tr background="img/back09.gif">
<td height="26" colspan="2"><table width="100%" height="26" border="0" cellpadding="0" cellspacing="0" background="img/back09.gif">
<tr>
<td width="23%" height="20" align="center" class="news02"><a href="index.jsp" class="news02">返回首页</a></td>
<td width="77%" class="news02">计划管理--局下达的综合计划</td>
</tr>
</table></td>
</tr>
<tr>
<td width="182" height="337" align="center" valign="top"><table width="95%" border="0" cellpadding="0" cellspacing="0" background="img/back0.gif">
<tr>
<td height="138" align="center" valign="top"><table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="img/jhgl.gif" width="177" height="61"></td>
</tr>
<tr>
<td height="66" align="left"><table width="95%" height="179" border="0" align="left" cellpadding="0" cellspacing="0" background="img/butt.gif">
<tr>
<td height="37" align="center" valign="middle" class="news02"> <a href="jhgl_zhjh.jsp" class="news02">局下达的综合计划</a></td>
</tr>
<tr>
<td height="37" align="center" valign="middle" class="news02"> 营销部的月度计划</td>
</tr>
<tr>
<td height="37" align="center" valign="middle" class="news02"> 各项生产计划</td>
</tr>
<tr>
<td height="37" align="center" valign="middle" class="news02"> 领导周(月)工作计划</td>
</tr>
<tr>
<td height="37" align="center" valign="middle" class="news02"> 班组周(月)工作计划</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="191" valign="bottom"><table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="5"><img src="img/back.gif" width="100%" height="9"></td>
</tr>
</table></td>
</tr>

</table></td>
<td width="618" valign="top"><table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td height="388" align="center" valign="top">

<table width="90%" border="0" cellspacing="0" cellpadding="0">
<%@ include file="ConnDB.jsp"%>
<tr>
<td colspan="2"> </td>
</tr>
<%

sql="select * from jhgl_xw where lxbh=1";
rs = stmt.executeQuery(sql);
if(rs.getRow()==0){out.print("对不起,您查找的栏目暂时没有内容!");}
else
{totalput=rs.getRow();
if(currentpage<1){currentpage=1;}
if((currentpage-1)*maxperpage>totalput)
{
if ((totalput%maxperpage)==0) {currentpage= totalput/maxperpage ;}
else currentpage= totalput/maxperpage+1 ;
}
if(currentpage==1){showcontent(maxperpage);showpage(totalput,maxperpage,"jhgl_zhjh");}
else{if((currentpage-1)*maxperpage<totalput)
{
rs.absolute((currentpage-1)*maxperpage);
showcontent(maxperpage);
showpage(totalput,maxperpage,"jhgl_zhjh");
}
else{
currentpage=1;
showcontent(maxperpage);
showpage(totalput,maxperpage,"jhgl_zhjh");
}
}
}
%>
<%
public void showcontent(int p)
{
try{
int i=0;
%>
<tr> <td width="79%" height="20" class="news02">  </td>
<td width="21%" height="20" align="center" class=news02> </td>
</tr>
<tr >
<td background="images/new-bg.gif" colspan="2" class="blank1" height="1"></td>
</tr>
<%
while((rs.next())&&i<=p)
{
%>
<tr>
<td width="79%" height="32" align="left" background="img/line00.gif">  <span class="news02">  <a href="jhgl_list.jsp?bh=<%=rs.getString("bh")%>" class="news02"><%=rs.getString("bt")%></a></span></td>
<td width="21%" align="center" class="news02"><%=rs.getString("rq")%></td>
</tr>
<% i=i+1;
}
%>
<tr>
<td height="25" colspan="2" class=news02 align=right>
<%
}catch(Exception e){System.out.println(e);}}


public void showpage(int totalnumber,int maxperpage,String filename)
{ int n=0;
if ((totalPut%maxperpage)==0) {n= totalPut/maxperpage ;}
else n= totalPut/maxperpage+1 ;
%>
<form method=Post action=<%=filename%>?page1=page.value>
<%
if(current<2){out.print("首页 上一页 ");}
else
{
%>
<a href=<%=filename%>?page1="1" class=news02>首页</a> 
<a href=<%=filename%>?page1=<%=Integer.toString(currentpage-1)%> class=news02>上一页</a> 
<%
}

if(n-currentpage<1){

out.print("下一页 尾页");}

else
{
%>
<a href=<%=filename%>?page1=<%=Integer.toString(currentpage+1)%> class=news02>下一页</a> 
<a href=<%=filename%>?page1=<%=Integer.toString(n)%> class=news02>尾页</a>  页次:<strong><font color=red><%=CurrentPage%></font><%=n%></strong>
<%
}
%>

转到:
<select name='page' size='1' style="font-size: 9pt" onChange='javascript:submit()'>
<%for(int i = 1; i<n;i++)
{
%>
<option value='<%=i%>' <%if (Integer.parseInt(Page1)==i){%> selected <%}%>><%=i%>/<%=n%></option>
<% } %>
</select>
<% } %>


</form>

</td>
</tr>
</table>

</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"><%@ include file="copy.jsp"%></td>
</tr>
</table>

</body>
</html>
<%
rs.close();stmt.close();conn.close();
%>
...全文
233 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dearkp 2006-09-22
  • 打赏
  • 举报
回复
就是调用两个函数出了问题,请问一下,jsp写函数是不是要用〈%! %〉包起来。我没加!所以出现那些问题,但是包了之后也不行,请问我的两个函数这样写可以吗?

<%!
public void showcontent(int p)
{
int i=0;
%>
<tr> <td width="79%" height="20" class="news02">  </td>
<td width="21%" height="20" align="center" class=news02> </td>
</tr>
<tr >
<td background="images/new-bg.gif" colspan="2" class="blank1" height="1"></td>
</tr>
<%
while((rs.next())&&i<=p)
{
%>
<tr>
<td width="79%"height="32"lign="left"background="img/line00.gif">  <span class="news02">  <a href="jhgl_list.jsp?bh=<%=rs.getString("bh")%>" class="news02"><%=rs.getString("bt")%></a></span>
</td>
<td width="21%" align="center" class="news02"><%=rs.getString("rq")%></td>
</tr>
<% i=i+1;
}
%>
<tr>
<td height="25" colspan="2" class=news02 align=right>
<%
}
%>

<%!

public void showpage(int totalnumber,int maxperpage,String filename)
{ int n=0;
if ((totalPut%maxperpage)==0) {n= totalPut/maxperpage ;}
else n= totalPut/maxperpage+1 ;
%>
<form method=Post action=<%=filename%>?page1=page.value>
<%
if(current<2){out.print("首页 上一页 ");}
else
{
%>
<a href=<%=filename%>?page1="1" class=news02>首页</a> 
<a href=<%=filename%>?page1=<%=Integer.toString(currentpage-1)%> class=news02>上一页</a> 
<%
}

if(n-currentpage<1){

out.print("下一页 尾页");}

else
{
%>
<a href=<%=filename%>?page1=<%=Integer.toString(currentpage+1)%> class=news02>下一页</a> 
<a href=<%=filename%>?page1=<%=Integer.toString(n)%> class=news02>尾页</a>  页次:<strong><font color=red><%=CurrentPage%></font><%=n%></strong>
<%
}
%>

转到:
<select name='page' size='1' style="font-size: 9pt" onChange='javascript:submit()'>
<%for(int i = 1; i<n;i++)
{
%>
<option value='<%=i%>' <%if (Integer.parseInt(Page1)==i){%> selected <%}%>><%=i%>/<%=n%></option>
<% } %>
</select>
<% } %>
imA 2006-09-22
  • 打赏
  • 举报
回复
提示的是很清楚嘛
/bm_cqgd2006/jhgl_zhjh.jsp line 128

有非法的表达式
dearkp 2006-09-22
  • 打赏
  • 举报
回复
不好意思,是这样的。直接把函数写在jsp页面里,然后调用。
public void showcontent(int p){}
public void showpage(int totalnumber,int maxperpage,String filename){}

这两个函数出错,出错信息
Compilation of 'E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java' failed:
--------------------------------------------------------------------------------
E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:280: illegal start of expression
probably occurred due to an error in /bm_cqgd2006/jhgl_zhjh.jsp line 128:
public void showcontent(int p)

E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:264: cannot resolve symbol
probably occurred due to an error in /bm_cqgd2006/jhgl_zhjh.jsp line 112:
if(currentpage==1){showcontent(maxperpage);showpage(totalput,maxperpage,"jhgl_zhjh");}

E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:264: cannot resolve symbol
probably occurred due to an error in /bm_cqgd2006/jhgl_zhjh.jsp line 112:
if(currentpage==1){showcontent(maxperpage);showpage(totalput,maxperpage,"jhgl_zhjh");}

E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:268: cannot resolve symbol
probably occurred due to an error in /bm_cqgd2006/jhgl_zhjh.jsp line 116:
showcontent(maxperpage);

E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:269: cannot resolve symbol
probably occurred due to an error in /bm_cqgd2006/jhgl_zhjh.jsp line 117:
showpage(totalput,maxperpage,"jhgl_zhjh");

E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:273: cannot resolve symbol
probably occurred due to an error in /bm_cqgd2006/jhgl_zhjh.jsp line 121:
showcontent(maxperpage);

E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:274: cannot resolve symbol
probably occurred due to an error in /bm_cqgd2006/jhgl_zhjh.jsp line 122:
showpage(totalput,maxperpage,"jhgl_zhjh");


--------------------------------------------------------------------------------
Full compiler error(s):
E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:280: illegal start of expression
public void showcontent(int p) //[ /bm_cqgd2006/jhgl_zhjh.jsp; Line: 128]
^
E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:264: cannot resolve symbol
symbol : method showcontent (int)
location: class jsp_servlet._bm_cqgd2006.__jhgl_zhjh
if(currentpage==1){showcontent(maxperpage);showpage(totalput,maxperpage,"jhgl_zhjh");} //[ /bm_cqgd2006/jhgl_zhjh.jsp; Line: 112]
^
E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:264: cannot resolve symbol
symbol : method showpage (int,int,java.lang.String)
location: class jsp_servlet._bm_cqgd2006.__jhgl_zhjh
if(currentpage==1){showcontent(maxperpage);showpage(totalput,maxperpage,"jhgl_zhjh");} //[ /bm_cqgd2006/jhgl_zhjh.jsp; Line: 112]
^
E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:268: cannot resolve symbol
symbol : method showcontent (int)
location: class jsp_servlet._bm_cqgd2006.__jhgl_zhjh
showcontent(maxperpage); //[ /bm_cqgd2006/jhgl_zhjh.jsp; Line: 116]
^
E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:269: cannot resolve symbol
symbol : method showpage (int,int,java.lang.String)
location: class jsp_servlet._bm_cqgd2006.__jhgl_zhjh
showpage(totalput,maxperpage,"jhgl_zhjh"); //[ /bm_cqgd2006/jhgl_zhjh.jsp; Line: 117]
^
E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:273: cannot resolve symbol
symbol : method showcontent (int)
location: class jsp_servlet._bm_cqgd2006.__jhgl_zhjh
showcontent(maxperpage); //[ /bm_cqgd2006/jhgl_zhjh.jsp; Line: 121]
^
E:\bea\bmwy\bmwy_domain\.\myserver\.wlnotdelete\extract\myserver_bmwyapp_bmwyapp\jsp_servlet\_bm_cqgd2006\__jhgl_zhjh.java:274: cannot resolve symbol
symbol : method showpage (int,int,java.lang.String)
location: class jsp_servlet._bm_cqgd2006.__jhgl_zhjh
showpage(totalput,maxperpage,"jhgl_zhjh"); //[ /bm_cqgd2006/jhgl_zhjh.jsp; Line: 122]
^
7 errors


--------------------------------------------------------------------------------
Fri Sep 22 16:24:09 CST 2006

jsp写函数是包在<%! %>里的,我的代码没写!,但是加了之后出错信息变了
如下
Parsing of JSP File '/bm_cqgd2006/jhgl_zhjh.jsp' failed:
--------------------------------------------------------------------------------
/bm_cqgd2006/jhgl_zhjh.jsp(153): scriptlet close brace '}' unbalanced at line 153 which breaks scope '_base_service_scope_'
probably occurred due to an error in /bm_cqgd2006/jhgl_zhjh.jsp line 153:
}catch(Exception e){System.out.println(e);}}
--------------------------------------------------------------------------------
Fri Sep 22 16:25:26 CST 2006
imA 2006-09-22
  • 打赏
  • 举报
回复
出错信息是什么?

你这样贴一堆代码,谁能有时间给一句一句的看呢。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧