一个很久没有解决的问题,请各位大哥大姐帮帮忙!谢谢.
下面是我做的查询分页显示代码,当我输入英文关键字是可以分页显示,但是我输入中文关键字是第一页可以显示,点下一页时就不好显示.
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<head>
<title>关键字查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="zhu/Template15.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<jsp:include page="fooder.jsp" flush="true"/>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="LoginBean" scope="page" class="DB.registerDB" />
<%
int PageSize=2; //一页显示的记录数
int RowCount; //记录总数
int PageCount; //总页数
int Page; //待显示页码
int i,j;
String q1,sql1,sql;
String strPage=request.getParameter("page");
if(strPage==null)
{
Page=1;
}else{
Page=Integer.parseInt(strPage);
if(Page<1) Page=1;
}
q1=request.getParameter("finder"); //从上一个页面接收的关键字
q1=new String(q1.getBytes("ISO8859-1"));
String q2=new String(q1);//分页时用到的关键字
q1="'%"+q1+"%'";
sql1="select count(*) from Book where Name like "+q1;
ResultSet rs1=LoginBean.perFORMSQL(sql1);
rs1.next();
RowCount=rs1.getInt(1);
rs1.close();
PageCount=(RowCount+PageSize-1)/PageSize;
if(Page>PageCount) Page=PageCount;
sql="select * from Book where Name like "+q1;
ResultSet rs=LoginBean.perFORMSQL(sql);
i=(Page-1)*PageSize;
for(j=0;j<i;j++) rs.next();
%>
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center" height="160">
<tr>
<td height="60" valign="top"> 当前位置:><a href="index.jsp">首页</a> 商品检索</td>
</tr>
<tr>
<td align="center" height="38" valign="top">
<p style="font-size:14px;font-color:#ffffff"><font color=yellow><B><font color="#3366FF">商品检索结果列表</font></B></font></p>
</td>
</tr>
<tr>
<td height="22" valign="middle" bgcolor="LightSlateGray">共有<%=RowCount%>条记录</td>
</tr>
<tr>
<td height="83" valign="top">
<table width="750" border="1" cellspacing="0" cellpadding="0" height="76" bordercolor="#6B7584" align="center">
<tr>
<td bgcolor="#6B7584" height="21" align="center" width="295"><font color="#FFFFFF">商品名称</font></td>
<td bgcolor="#6B7584" height="21" width="90" align="center"><font color="#FFFFFF">规格</font></td>
<td bgcolor="#6B7584" height="21" width="40" align="center"><font color="#FFFFFF">单位</font></td>
<td bgcolor="#6B7584" height="21" width="59" align="center"><font color="#FFFFFF">市场价</font></td>
<td bgcolor="#6B7584" height="21" width="59" align="center"><font color="#FFFFFF">优惠价</font></td>
<td bgcolor="#6B7584" height="21" width="79" align="center"><font color="#FFFFFF">购买数量</font></td>
<td bgcolor="#6B7584" height="21" width="117" align="center"><font color="#FFFFFF">操作</font></td>
</tr>
<%
i=0;
while(i<PageSize&&rs.next())
{ String index=rs.getString("ID");
%>
<tr>
<td height="21" width="295"><A href="display.jsp?bookid=<%=index%>"><%out.print(rs.getString("Name"));%></A></td>
<td height="21" width="90">16开</td>
<td height="21" width="40">本</td>
<td height="21" width="59"><%out.print(rs.getFloat("MarketPrice"));%></td>
<td height="21" width="59"><font color=red ><%out.print(rs.getFloat("Price"));%></font></td>
<td height="21" width="79"> </td>
<td height="21" width="117"><a href="add.jsp?ProID=<%=index%>"><img src="zhu/Basket.gif" width="31" height="20" border="0"></a></td>
</tr>
<%
i++;}
rs.close();
%>
<tr bgcolor="LightSlateGray">
<td height="21" colspan="7">第<%=Page%>页 共<%=PageCount%>页
<% if(Page<PageCount){%>
<A href="find.jsp?page=<%=Page+1%>&finder=<%=q2%>">下一页</A>
<%}%>
<% if(Page>1){%>
<A href="find.jsp?page=<%=Page-1%>&finder=<%=q2%>">上一页</A>
<%}%>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<br>
<HR SIZE=1 width=760>
<jsp:include page="header.jsp" flush="true"/>
</body>
</html>