• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Jsp分页

servlet/jsp 搞代码 7年前 (2018-06-18) 180次浏览 已收录 0个评论

<%@ page contentType=”text/html;charset=gb2312″%>
<%
//变量声明
java.sql.Connection sqlCon; //数据库连接对象
java.sql.Statement sqlStmt; //SQL语句对象
java.sql.ResultSet sqlRst; //结果集对象

http://www.gaodaima.com/?p=44745jsp分页

java.lang.String strCon; //数据库连接字符串
java.lang.String strSQL; //SQL语句
int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
int rowi;
java.lang.String strPage;
int i,j,k; 
rowi=0;
String PageSize = (String) session.getValue(“pageSize”);

 

//if(PageSize!=null){
intPageSize=Integer.parseInt(PageSize);
strPage = request.getParameter(“page”);  //取得待显示页码
if(strPage==null){
//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
} else{
//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1; }
//装载JDBC驱动程序
Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver”);
//设置数据库连接字符串
strCon =”jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=sunmoon” ;
//连接数据库
sqlCon = java.sql.DriverManager.getConnection(strCon,”sa”,”sa”);
//创建SQL语句对象
sqlStmt = sqlCon.createStatement();
//获取记录总数 
 

 String companyName = (String) session.getValue(“companyName”);
 
if (“全部客户”.equals(companyName))
{
    strSQL = “select count(*) from customer”;
 
}

else 
{
 strSQL = “select count(*) from customer where 客户名称='”+companyName+”‘”;
 
}

//strSQL = “select count(*) from loadweight where 收货方='”+company+”‘ “;
sqlRst = sqlStmt.executeQuery(strSQL);
//执行SQL语句并取得结果集
sqlRst.next(); //记录集刚打开的时候,指针位于第一条记录之前
intRowCount = sqlRst.getInt(1);
sqlRst.close(); //关闭结果集
//记算总页数
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
//设置获取数据SQL语句
//strSQL = “select * from loadweight where 收货方=’广州世经'”;
{
 if (“全部客户”.equals(companyName))
 
    {
  strSQL = “select * from customer order by 客户序号”;

  }
 else
 {
  strSQL = “select * from customer where 客户名称='”+companyName+”‘ order by 客户序号”;
 }

 //strSQL = strSQL+” and 时间 between ‘2003-3-1’ and ‘2003-4-1’ “;
 //out.println(strSQL);
 
}
//执行SQL语句并取得结果集
sqlRst = sqlStmt.executeQuery(strSQL);
//将记录指针定位到待显示页的第一条记录上
i = (intPage-1) * intPageSize;
for(j=0;j<i;j++) sqlRst.next(); %>
<html>

<link href=”../../css/style.css” rel=”stylesheet” type=”text/css”>

<head>
<title>数据库查询系统</title>
</head>
<Script Language=JavaScript>
  function selectRow(oCurrent)
           {
        oCurrent.style.backgroundColor=”CCCCFF”;

        for(var i = 0; i < document.all(‘t1’).rows.length;i++)
         {

       if(t1.rows[i] != oCurrent) t1.rows[i].style.backgroundColor=”ffffff”;
         }
          }
 
 
 function moveto(page)
 {
  form1.action = “/sunmoon/jsp/inside/customer/customdbqueary.jsp?page=” + page;
  form1.method = “post”;
  form1.submit();
 }
   function printPage() { print(document); }
</Script>
<body>
<table width=”90%” border=”0″ align=”center”>
  <tr>
    <td nowrap>
<div align=”center”><strong><font color=”#660099″ size=”4″ face=”宋体”>系统查询结果</font></strong></div></td>
  </tr>
</table>
<p align=center><strong></strong></p>

<table width=90% border=0 align=center cellpadding=0 cellspacing=0 id=t1>
  <tr>
    <td width=”104″ height=”16″ align=center  nowrap bgcolor=”#FFFFCC”> <div align=”left”><font color=”#0000FF”>编号</font></div></td>
    <td width=60 align=center  nowrap bgcolor=”#FFFFCC”> <div align=”left”><font color=”#0000FF”>客户名称</font></div></td>
    <td width=”103″ align=center nowrap bgcolor=”#FFFFCC”> <div align=”left”><font color=”#0000FF”>账号</font></div></td>
    <td width=”117″ align=center nowrap bgcolor=”#FFFFCC”> <div align=”left”><font color=”#0000FF”>税号</font></div></td>
    <td width=”117″ align=center nowrap bgcolor=”#FFFFCC”> <div align=”left”><font color=”#0000FF”>开户行</font></div></td>
    <td width=”86″ align=center nowrap bgcolor=”#FFFFCC”> <div align=”left”><font color=”#0000FF”>电话号码</font></div></td>
    <td width=”100″ align=center nowrap bgcolor=”#FFFFCC”> <div align=”left”><font color=”#0000FF”>详单</font></div></td>
  </tr>
  <%
//显示数据

i = 0;
while(i<intPageSize && sqlRst.next()){rowi=rowi+1; %>
    <% if(rowi%2==0)
 {
    out.print(“<tr bgcolor=#CCCCFF onmouseover=selectRow(this)>”);
 }
 else
 {
 //out.print(“<tr “>;
 }
 %>
    <td height=”18″ valign=”top” nowrap><%=sqlRst.getString(“客户序号”)%></td>
    <td valign=”top” nowrap><%=sqlRst.getString(“客户名称”)%></td>
    <td nowrap><%=sqlRst.getString(“账号”)%></td>
    <td nowrap><%=sqlRst.getString(“税号”)%></td>
    <td nowrap><%=sqlRst.getString(“开户行”)%></td>
    <td nowrap><%=sqlRst.getString(“电话号码”)%></td>
    <%   String customname=sqlRst.getString(“客户序号”);  
    out.print(“<td width=9% nowrap><a href=customsingle.jsp?customer=”+customname+”>详单</a></td>”);
 %>
  </tr>
  <% i++; } %>
  <tr bgcolor=”#FFCCFF”>
    <td height=”18″ colspan=7 align=right> <div align=”right”><font color=”#0000FF”>第<%=intPage%>页 共<%=intPageCount%>页 <a href=”customdbqueary.jsp?page=1″>首页</a>
        <%if(intPage>1){%>
        <a href=”customdbqueary.jsp?page=<%=intPage-1%>”>上一页</a>
        <%
}
%>
        <%if(intPage<intPageCount){%>
        <a href=”customdbqueary.jsp?page=<%=intPage+1%>”>下一页</a>
        <%
}
%>
        <a href=”customdbqueary.jsp?page=<%=intPageCount%>”>尾页 </a>
        </font> </div></td>
    <td> </td>
  </tr>
  <tr align=”right”>
    <td height=”22″ colspan=”8″  align=”right”  valign=”top” nowrap bgcolor=”#FFFFFF”>
      <form name=”form1″ method=”post” action=”” >
        <font color=”#0000FF”>转到第
        <input type=text name=page size=2 maxlength=3 value=” style=’height:16;vertical-align:8%’>
        页
        <input class=buttonface type=Submit value=’Go’>
        </font> </form></td>
  </tr>
  <tr align=”right”>
    <td height=”22″ colspan=”8″ align=”right” valign=”top”> <input  class=buttonface value=”打印” type=”button” ></td>
  </tr>
</table>

</body>

</html>
<%
//关闭结果集
sqlRst.close();
//关闭SQL语句对象
sqlStmt.close();
//关闭数据库
sqlCon.close();
%>

 

欢迎大家阅读《Jsp分页》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Jsp分页

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址