⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 displaybytype.jsp

📁 用java写的网上售书系统 功能详尽 支持各种类别书目查询 分页显示 购物车的暂存功能 内部附有数据库
💻 JSP
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<%@page import="java.sql.*"%>
<jsp:useBean id="alogin" class="login.jdbcBean" scope="page"/>
<link href="myCss.css" rel="stylesheet" type="text/css" />
<link href="mytable.css" rel="stylesheet" type="text/css" />
<title>无标题文档</title>
</head>
<%
String type=request.getParameter("type");
String search=request.getParameter("search");
if(search!=null){
search=new String(search.getBytes("iso-8859-1"),"gb2312");
System.out.println(search);
}
String sql;
if(type.equals("0")){sql="select * from books where bookName like '%"+search+"%'";}
else{
if(search==null)sql="select * from books where typeID = '"+type+"'";

else sql="select * from books where typeID = '"+type+"'"+" and bookName like '%"+search+"%'";
}
ResultSet rs;
rs=alogin.executeQuery(sql);
//System.out.println(sql);

  int intPageSize; //一页显示的记录数

  int intRowCount; //记录总数

  int intPageCount;//总页数
 
  int intPage; //待显示页码
  
  String  strPage; 
  
  int i; 
  
 intPageSize =10; //设置一页显示的记录数 
 strPage = request.getParameter("page"); //取得待显示页码 

if(strPage==null){ //表明在QueryString中没有page这一个参数,此时显示第一页数据
  intPage = 1; 
  } else{//将字符串转换成整型
 intPage = java.lang.Integer.parseInt(strPage); 
}
if(intPage< 1){
intPage = 1; 
} 

rs.last(); //获取记录总数 
intRowCount = rs.getRow(); //记算总页数 
intPageCount = (intRowCount+intPageSize-1) / intPageSize; //调整待显示的页码 

if(intPage >intPageCount) intPage = intPageCount; 
if(intPageCount >0){ 
//将记录指针定位到待显示页的第一条记录上 
rs.absolute((intPage-1) * intPageSize+1); 
//显示数据 
}

%>
<body class="myCss">
<div>
  
  <p align="center"><br />&nbsp;</p>
  <p align="center">以下便是你所要的查询结果如下-</p>
</div>
<table width="860" border="1" cellpadding="1" cellspacing="0" bordercolor="#CCCCFF" class="mytable">
  <tr>
    <td width="830" height="30"><div align="center">
      <p>bookName</p>
      </div></td>
    <td width="830" height="30"><div align="center">
      <p>publisher</p>
      </div></td>
    <td width="830" height="30"><div align="center">
      <p>price</p>
      </div></td>
    <td width="830" height="30"><div align="center">
      <p>vipPrice</p>
      </div></td>
    <td width="830" height="30"><div align="center">
      <p>author</p>
      </div></td>
    <td width="830" height="30"><div align="center">
      <p>pagNum</p>
      </div></td>
  </tr>
  <%
i = 0; if(intRowCount==0){i=intPageSize;}
while(i< intPageSize && !rs.isAfterLast()){
%>
  <tr>
    <td height="20"><div align="center"><a href="bookDetail.jsp?bookID=<%=rs.getString("bookID")%>"><%=rs.getString("bookName")%></a>&nbsp;</div></td>
    <td height="20"><div align="center"><%=rs.getString("publisher")%>&nbsp;</div></td>
    <td height="20"><div align="center"><%=rs.getString("price")%>&nbsp;</div></td>
    <td height="20"><div align="center"><%=rs.getString("vipPrice")%>&nbsp;</div></td>
    <td height="20"><div align="center"><%=rs.getString("author")%>&nbsp;</div></td>
    <td height="20"><div align="center"><%=rs.getString("pagNum")%>&nbsp;</div></td>
  </tr>
  <%if(rs.next());i++;}
  rs.close();
  alogin.closeDateBase();
  %>
</table>
<p align="center">
	共<%=intRowCount%>个记录,分<%=intPageCount%>页显示,当前页是:第<%=intPage%>页
<%//int Int_type=Integer.parseInt(type);
for(int j=1;j<=intPageCount;j++)
{//out.print("&nbsp;&nbsp;<a href='displayByType.jsp?page="+j+"&type="+type+"'>"+j+"</a>");
if(search==null)out.print("&nbsp;&nbsp;<a href='displayByType.jsp?page="+j+"&type="+type+"'>"+j+"</a>");
else out.print("&nbsp;&nbsp;<a href='displayByType.jsp?page="+j+"&type="+type+"&search="+search+"'>"+j+"</a>");
}
%>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -