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

📄 showbytype.jsp

📁 一个简单实用的网上书城,可当作原型使用
💻 JSP
字号:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page language="java"import="java.sql.*" %>
<%@ page language="java"import="java.net.URLEncoder" %>
<jsp:useBean class="czm.BookBean" id="book" scope="page"></jsp:useBean>
<HTML>
<HEAD>
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE>
数据库 On Line -member:<%= session.getValue("memberID") %>
</TITLE>
<SCRIPT language="javaScript">
<!--
function openwin(str)
{	window.open("addcart.jsp?ISBN="+str,  
"shoppingcart","width=300,height=200,resizable=1,scrollbars=2");
	return;
}
function openwint(str)
{	window.open("addtem.jsp?ISBN="+str,  
"shoucang","width=300,height=200,resizable=1,scrollbars=2");
	return;
}
//-->
</SCRIPT>
    <script language="javascript">
        function check(){
        if(bookList.chaxun.value==""){
                alert("请输入要查找书本的名字呀");
                return false;
                }
          else return true;
          }
    </script>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
    <form name="bookList" action="findbyName.jsp" onSubmit="return check()">
   <%
        if (session.getValue("memberID") == null||"".equals(session.getValue("memberID"))){
        %>
            <H2 align="center">请先登录,然后再选书</H2>
            <H2 align="center"><A href="default.html">登录</A></H2>
        <%
        }
        else{
            request.setCharacterEncoding("UTF-8");            
            String ty=request.getParameter("type");           
        %>        
            <H1 align="center">网上书城</H1>
        <br>
        <a href="booklist.jsp">返回</a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <tr>      
        输入书名:<input type="text" name="chaxun" value="" />
        <input type="radio" name="mhjq" value="mohu" checked />模糊
        <input type="radio" name="mhjq" value="jingque" />精确
        <input type="submit" value="查询" name="submit2" />
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        </tr>  
            </br>
           <tr align="left"><td><font color="green">分类:</td>
              </br>  &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 
            <td>
 <%
    String sql="Select distinct book_type from bookInfo ";
    String booktype="";
    ResultSet rrs = book.executeQuery(sql);
    while(rrs.next()){
     	booktype= rrs.getString("book_type");        
        String tt=URLEncoder.encode(booktype,"UTF-8");
%>
        <a href="showBytype.jsp?type=<%=tt%>"><%=booktype%></a>
          <%
    }
    if(ty==null) ty=booktype;
%>
        </td></tr> 
<table width="100%" border="1" cellspacing="0" bordercolor="#9999FF">
    <tr align="left"><%=ty%>:</tr>
    <hr>
    <tr align="left">
        <%
     ResultSet rs2 = book.getBookListbyType(ty);
    
    rs2.last();
	//得到当前行的行数,也就得到了数据库中留言的总数。
	int rowCount=rs2.getRow();
        //表示当前的页数。
        int curPage=1;
        //定义每页显示的留言数。
        int countPerPage=10;
        int pageCount=0;        
	if(rowCount==0)
	{
		out.println("当前没有任何书籍!");
		//return;
	}else{
               ty = URLEncoder.encode(ty,"UTF-8");
               String strCurPage=request.getParameter("page");
               if(strCurPage==null)
                    curPage=1;
                else
                    curPage=Integer.parseInt(strCurPage);
                //计算显示所有留言需要的总页数。
                pageCount=(rowCount+countPerPage-1)/countPerPage;
                //移动游标至结果集中指定的行。如果显示的是第一页,curPage=1,
                //游标移动到第1行。
                rs2.absolute((curPage-1)*countPerPage+1);
                out.println("共"+rowCount+"种书");
                %>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <%
                //如果是第1页,则显示不带链接的文字,如果不是第1页,
                //则给用户提供跳转到第一页和上一页的链接。                                
                if(curPage==1){ 
                %>
                        首页&nbsp;&nbsp;&nbsp;&nbsp;
                        上一页&nbsp;&nbsp;&nbsp;&nbsp;
                <%
                }else {
                %>
                    <a href="showBytype.jsp?type=<%=ty%>&page=<%=1%>">首页</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="showBytype.jsp?type=<%=ty%>&page=<%=curPage-1%>">上一页</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                <%
                }
                //如果当前页是最后一页,则显示不带链接的文字,如果不是最后一页,
                //则给用户提供跳转到最后一页和下一页的链接。
                if(curPage==pageCount)
                {
                %>
                        下一页&nbsp;&nbsp;&nbsp;&nbsp;
                        尾页&nbsp;&nbsp;&nbsp;&nbsp;
                <%
                }else{
                %>
                        <a href="showBytype.jsp?type=<%=ty%>&page=<%=curPage+1%>">下一页</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="showBytype.jsp?type=<%=ty%>&page=<%=pageCount%>">尾页</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                <%
                }
                out.println("页次: "+curPage+"/"+pageCount+"页");
                %>
    </tr>
  <tr bgcolor="#FFFFCC"> 
    <td><font color="#3333FF">ISBN</font></td>
    <td><font color="#3333FF">书名</font></td>
    <td><font color="#3333FF">作者</font></td>
    <td><font color="#3333FF">出版社</font></td>
    <td><font color="#3333FF">定价</font></td>    
    <td>&nbsp;</td>
  </tr>
  
  <%
    int i=0;
    //以循环的方式取出每页要显示的数据,因为在前面针对要显示的页数,
    //调用了rs.absolute((curPage-1)*countPerPage+1);
    //所以是从游标所在的位置取出当前页要显示的数据。
    while(i<countPerPage && !rs2.isAfterLast()){
     	String ISBN = rs2.getString("bookISBN");
    %> 
  <tr> 
    <td><%=ISBN%></td>
    <td><a href="bookinfo.jsp?ISBN=<%=ISBN%>"><%= rs2.getString("bookName")%></A></td>
    <td><%= rs2.getString("bookAuthor")%></td>
    <td><%= rs2.getString("publisher")%></td>
    <td><%= rs2.getString("price")%></td>
    <td><a href="javascript:openwin('<%=ISBN%>')">加入购物车</a>&nbsp;&nbsp;<a href="javascript:openwint('<%=ISBN%>')">收藏</a></td>
  </tr>
  <%
     i++;
     rs2.next();
   }
     rs2.close();
%>
</table><hr>
<%
                 out.println("共"+rowCount+"种书");
                %>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <%
                //如果是第1页,则显示不带链接的文字,如果不是第1页,
                //则给用户提供跳转到第一页和上一页的链接。
                if(curPage==1)
                { 
                %>
                        首页&nbsp;&nbsp;&nbsp;&nbsp;
                        上一页&nbsp;&nbsp;&nbsp;&nbsp;
                <%
                }else{
                %>
                    <a href="showBytype.jsp?type=<%=ty%>&page=<%=1%>">首页</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="showBytype.jsp?type=<%=ty%>&page=<%=curPage-1%>">上一页</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                <%
                }
                //如果当前页是最后一页,则显示不带链接的文字,如果不是最后一页,
                //则给用户提供跳转到最后一页和下一页的链接。
                if(curPage==pageCount)
                {
                %>
                        下一页&nbsp;&nbsp;&nbsp;&nbsp;
                        尾页&nbsp;&nbsp;&nbsp;&nbsp;
                <%
                }else{
                %>
                        <a href="showBytype.jsp?type=<%=ty%>&page=<%=curPage+1%>">下一页</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="showBytype.jsp?type=<%=ty%>&page=<%=pageCount%>">尾页</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
            <%
                }
                out.println("页次: "+curPage+"/"+pageCount+"页");
             }
            %>
            <hr>
</table>
<table align="center" border="0">
  <tbody> 
  <tr> 
    <td><a href="shoppingcart.jsp"><font color="#0000FF">查看购物车</font></a></td>
    <td>&nbsp;&nbsp;</td>
    <td width="108"><a href="shoucang.jsp"><font color="#0000FF">查看收藏夹</font></a></td>
  </tr>
  </tbody> 
</table>
<p>&nbsp;</p>
<%
}
%>
</form>
</BODY>
</HTML>

⌨️ 快捷键说明

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