为什么在上一页,下一页都正常的情况下,输入页数查找时“对不起,没有符合搜索条件的记录!”现将全部代码贴出来,希望帮忙找找原因,修改下
<%@ include file="conn.jsp"%>
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%request.setCharacterEncoding("gb2312");
String key=request.getParameter("key");
String stype=request.getParameter("stype");
String gzdd=request.getParameter("gzdd");
String stype1="company" ;
String gzdd1="noxz" ;
if(key==null){
key="";
}
 %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<link rel="stylesheet" href="inc/index.css" type="text/css">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>滁州人才==&gt;人才市场==&gt;站内搜索</title>
</head>
<body topmargin="0" leftmargin="0">
<SCRIPT language=JavaScript src="inc/f-index.js"></SCRIPT>
<div align="center">
  <table border="0" cellpadding="0" cellspacing="0" height="358">
    <tr>     
      <td width="293" height="284" valign="top">
<% 
int intPageSize;
int intRowCount;//记录总数
int intPageCount;//总页数
int intPage;//页面参数
String strPage;//定义变量用来传递page
int i;
intPageSize=5;//定义每页显示5条记录
strPage=request.getParameter("page");//取得当前的页码
if(strPage==null){//判断初始页面,如果没有显示记录,就置为第一页
intPage=1;
}else{
intPage=Integer.parseInt(strPage);//将strPage转化为整数
if(intPage<1) intPage=1;
}
String sqlname,sqlname1;
if(stype1.equals(stype)){
    if(gzdd1.equals(gzdd)){
     sqlname="select * from company where job  like '%"+key+"%' or cname like '%"+key+"%' and job is not null  order by id desc" ;
    sqlname1="select count(id) from company where job  like '%"+key+"%' or cname like '%"+key+"%' and job is not null  order by id desc" ;
}else{
           sqlname="select * from company where (job like '%"+key+"%' or cname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ; 
   sqlname1="select count(id) from company where (job like '%"+key+"%' or cname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ;
}
}else
           { 
  if(gzdd1.equals(gzdd)){
              sqlname="select * from person where job  like '%"+key+"%' or iname like '%"+key+"%' and job is not null  order by id desc" ;
  sqlname1="select count(id) from person where job  like '%"+key+"%' or iname like '%"+key+"%' and job is not null  order by id desc" ;
              }else{ 
              sqlname="select * from person where (job  like '%"+key+"%' or iname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ; 
  sqlname1="select count(id) from person where (job  like '%"+key+"%' or iname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ;
              }
}
ResultSet rt=stmt.executeQuery(sqlname1);
rt.next();
intRowCount=rt.getInt(1);//取得整数保存与intRowCount变量中
intPageCount=(intRowCount+intPageSize-1)/intPageSize;//计算出总页数(记录总数+每页显示的记录-1)/每页显示的记录)
if(intPage>intPageCount)  //输入的页数大于总页数
intPage=intPageCount;
ResultSet rs=stmt.executeQuery(sqlname);
if(intRowCount==0){
out.print("<SCRIPT language=JavaScript>alert('对不起,没有符合搜索条件的记录!');");
out.print("javascript:history.go(-1)</SCRIPT>");   
  }  else{     //打扩号直接扩到最后
          %>     
        <div align="left">
         <table border="1" cellpadding="0" cellspacing="0" width="430" bordercolor="#FFFFFF">
          <tr>
          <td height="17" colspan="3" valign="bottom" width="426"></td> 
          </tr>
          <tr>         
 <td width="426" height="6" colspan="3" valign="bottom"><font color="#000000"></font>
         共有[<font color="#ff0000"><%=intRowCount%></font>]条 页/次:<font color="#0000AE"><%=intPage%></font>/<%=intPageCount%></td>           
          </tr>
          <tr> 
  <td width="426" height="6" colspan="3" valign="bottom">
<FORM name="go2to" action=search.jsp method=POST>
            <p align='center'>
第<%=intPage%>页 &nbsp;&nbsp;&nbsp;共<%=intPageCount%>页&nbsp;&nbsp;&nbsp;
<%if(intPage<intPageCount){%>
<a href="search.jsp?page=<%=intPage+1%>&key=<%=key%>&stype=<%=stype%>&gzdd=<%=gzdd%>">下一页</a>&nbsp;&nbsp;&nbsp;
<%}%>
<%if(intPage>1){%>
<a href="search.jsp?page=<%=intPage-1%>&key=<%=key%>&stype=<%=stype%>&gzdd=<%=gzdd%>">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%}%>
转到<input type="text" name="page" size="3">页    &nbsp;
<input type="button" name="sure" value="确定 " onClick=checknum()>
    </form>          
             </td>          
           </tr> 
            <%  
            if(stype1.equals(stype)){%>
          <tr>
          <td height="3" valign="top" colspan="3" bgcolor="#000000"></td>
          </tr>
  <tr>
          <td width="174" height="18" bgcolor="#EBEEF3" valign="bottom">&nbsp;公司名称</td>
          <td width="174" height="18" bgcolor="#EBEEF3" valign="bottom">&nbsp;招聘职位</td>
          <td height="18" bgcolor="#EBEEF3" width="75"><p align="center">发布日期</p></td>
          </tr>
           <%rs.absolute((intPage-1)*intPageSize+1);
     i=0;
   while(i<intPageSize&&!rs.isAfterLast()){
       %>
          <tr>
          <td width="174" height="18" bgcolor="#EBEEF3" valign="bottom">&nbsp;<a href="javascript:openwin('company.jsp?uid=<%=rs.getString("uname")%>','top=10,left=80,width=460,height=420')"><%=rs.getString("cname")%></a></td>
          <td width="174" height="18" bgcolor="#EBEEF3" valign="bottom">&nbsp;<a href="javascript:openwin('job.jsp?uid=<%=rs.getString("uname")%>','top=10,left=80,width=460,height=420')"><%=rs.getString("job")%></a></td>
          <td width="74" height="18" bgcolor="#EBEEF3" valign="bottom"><p align="center"><%=rs.getString("idate")%></p></td>
          </tr>
 <% rs.next();
    i++;
} %>
          <tr>
      <td height="3" valign="top" colspan="3" bgcolor="#000000"></td>
          </tr>
          <tr>
          <td width="422" height="8" valign="bottom" colspan="3">
            <p align="center"><br>
            【<a href="javascript:window.close()">关闭窗口</a>】</td>
          </tr>
  </table>
          </div>
  <% }  
           
          else {%>
           <div align="left">
  <table border="1" cellpadding="0" cellspacing="0" width="430" bordercolor="#FFFFFF">
        <tr>
      <td height="3" valign="top" colspan="5" bgcolor="#000000">
      </td>
        </tr>
        <tr>
          <td width="67" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="left">&nbsp;姓名</p>   
          </td>
          <td width="45" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="center">性 别</p>  
          </td>
          <td width="56" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="center">学 历   
          </td>
          <td width="178" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="left">&nbsp;应聘职位</td>
          <td width="75" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="center">登录日期</p>
       </td>
        </tr>
         <%       rs.absolute((intPage-1)*intPageSize+1);
i=0;
while(i<intPageSize&&!rs.isAfterLast()){
%>
        <tr>
          <td width="64" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="left">&nbsp;<a href="javascript:openwin('person.jsp?uid=<%=rs.getString("uname")%>','top=10,left=80,width=460,height=420')"><%=rs.getString("iname")%></a></p>
          </td>
          <td width="48" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="center">[<%=rs.getString("sex")%>]</p>
          </td>
          <td width="55" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="center">[<%=rs.getString("edu")%>]</td>
          <td width="179" height="18" bgcolor="#EBEEF3" valign="bottom">&nbsp;<%=rs.getString("job")%></td>
          <td width="72" height="18" bgcolor="#EBEEF3" valign="bottom">
            <p align="center"><%=rs.getString("idate")%></p>
          </td>
        </tr>
        <% rs.next();
           i++;
} %>
          <tr>
      <td height="3" valign="top" colspan="5" bgcolor="#000000"></td>
          </tr>
          <tr>
          <td width="418" height="7" valign="bottom" colspan="5">
            <p align="center"><br>
            【<a href="javascript:window.close()">关闭窗口</a>】
          </td>
          </tr>
        </table>
        </div>
<%}
}%>
      </td>
    </tr>
</table>
</div>
</body>
</html>

解决方案 »

  1.   

    if(intRowCount==0){
    out.print("<SCRIPT language=JavaScript>alert('对不起,没有符合搜索条件的记录!');");
    这个条件成立了呗   看看sql能查出什么  上数据库里 试下 sql
      

  2.   

    如果这个条件成立,那为什么我的上下页功能正常使用呢?如果查不到数据,intPage+1或intPage-1也就不会显示对应的数据了