大项目之网上书城(十二)——完成啦

目录

  • 大项目之网上书城(十二)——完成啦

    • 主要改动
    • 新增代码
      • 1.addCategory.jsp
      • 效果图
      • 2.bookManager.jsp
      • 效果图
      • 3.userManager.jsp
      • 效果图
      • 4.error404.jsp
      • 效果图
      • 5.error500.jsp
      • 效果图
      • 6.errorelse.jsp
      • 效果图
      • 7.web.xml
      • 8.addFenLeiServlet
      • 9.bookDao里的addFenLei
    • 总结
    • github页面
      • bookstoreZhang

大项目之网上书城(十二)——完成啦

主要改动

管理员添加分类,管理图书,管理用户。以及往数据库里填了几十本书。添加了错误页面。

新增代码

1.addCategory.jsp

因为之前给每个分类都建了表,而且每个表都有自己的文件夹。于是,添加分类好麻烦啊。具体见servlet

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>空白</title>

</head>
<%
    if(request.getSession().getAttribute("root")==null){
        response.sendRedirect(request.getContextPath()+"/client/login.jsp");
    }else{
%>
<body style="background-color:#bbb;width:1400px;margin:0 auto">
<!-- 调用头部页面 -->
<div style="width:100%;height:100px;float:left">
<jsp:include page="/admin/head.jsp"></jsp:include>
</div>
<!-- 通用内容体大小 -->
<div style="width:70%;height:720px;float:left;margin-left:15%;">
<!-- 好看的图 -->
    <div style="width:55%;height:100%;float:left;margin-top:10%;">
        <img alt="书架" src="${pageContext.request.contextPath }/client/img/bookshelf.jpg" style="width:90%;">
    </div>
    <!-- 添加界面 -->
    <div style="width:45%;height:80%;float:left;margin-top:12%">
        <h1 style="color:#8b6914;text-align:center">添加分类</h1>
        <hr style="height:2px;border:none;border-top:5px ridge green;" />
        <form action="${pageContext.request.contextPath }/AddFenLei" method="post" class="form-horizontal" role="form">
            <div class="form-group">
                <label for="lastname" class="col-sm-3 control-label input-lg">分类名</label>
                <div class="col-sm-9">
                    <input type="text" name="fenlei_name" id="fenlei_name" class="form-control input-lg"
                           placeholder="请输入分类名" style="float:left"/>
                </div>
            </div>
            <div class="form-group">
                <label for="firstname" class="col-sm-3 control-label input-lg">英文名</label>
                <div class="col-sm-9">
                    <input type="text" name="feilei_table" id="fenlei_table"
                    class="form-control input-lg" placeholder="请输入英文名" style="float:left"/>
                </div>
            </div>
            <div class="form-group">
            <label for="firstname" class="col-sm-4 control-label input-lg"></label>
            <div class="col-sm-5">
                <input type="submit" name="submit" value="添加分类"
                class="form-control input-lg btn btn-warning"style="width:100%;float:left"/>
            </div>
        </div>
        </form>
    </div>
</div>
<!-- 调用底部页面 -->
<div style="width:100%;height:60px;float:left">
<jsp:include page="/admin/foot.jsp"></jsp:include>
</div>
</body>
<%} %>
</html>

效果图

2.bookManager.jsp

有点赶,就只简单写了个分类,没有分页,用加滚动条混过去吧。。

<%@page import="cn.edu.bdu.mc.beans.FenLei"%>
<%@page import="cn.edu.bdu.mc.daos.impls.FenLeiDaoImpl"%>
<%@page import="cn.edu.bdu.mc.daos.FenLeiDao"%>
<%@page import="cn.edu.bdu.mc.daos.impls.BookDaoImpl"%>
<%@page import="cn.edu.bdu.mc.daos.BookDao"%>
<%@page import="cn.edu.bdu.mc.beans.Book"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>图书管理</title>

</head>
<%
    if(request.getSession().getAttribute("root")==null){
        response.sendRedirect(request.getContextPath()+"/client/login.jsp");
    }else{
        FenLeiDao fenLeiDao = new FenLeiDaoImpl();
        List<FenLei>fenleis = fenLeiDao.findAllFenLei();
        List<Book>books = null;
        BookDao bookDao = new BookDaoImpl();
        String clazz = request.getParameter("clazz");
        if(clazz==null){
            books = bookDao.findAllBook();
        }else{
            books = bookDao.findBookByClazz(clazz);
        }
%>
<body style="background-color:#bbb;width:1400px;margin:0 auto">
<!-- 调用头部页面 -->
<div style="width:100%;height:100px;float:left">
<jsp:include page="/admin/head.jsp"></jsp:include>
</div>
<!-- 通用内容体大小 -->
<div class="pre-scrollable" style="width:70%;height:720px;float:left;margin-left:15%;overflow:auto;">
    <div class="panel panel-info">
        <div class="panel-heading">
            <div class="dropdown panel-title">
                  <a class="dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" >
                        <font color="black">图书类别</font>
                    <span class="caret"></span>
                  </a>
                  <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                    <li><a href="${pageContext.request.contextPath }/admin/bookManager.jsp">全部图书</a></li>
                    <li role="separator" class="divider"></li>
                    <%
                        for(FenLei fenlei:fenleis){
                    %>
                    <li><a href="${pageContext.request.contextPath }/admin/bookManager.jsp?clazz=<%=fenlei.getFenlei_table() %>"><%=fenlei.getFenlei_name() %></a></li>
                    <%} %>
                  </ul>
                </div>
        </div>
        <table class="table">
            <tr>
                <th>书名</th>
                <th>价格</th>
                <th>类别</th>
                <th>数量</th>
                <th>描述</th>
                <th>操作</th>
            </tr>
        <%
        for(Book book:books){
        %>
            <tr>
                <td><%=book.getBook_name() %></td>
                <td><%=book.getPrice() %>&nbsp;元</td>
                <td><%=book.getClazz() %></td>
                <td><%=book.getCount() %></td>
                <td><%=book.getDescribtion() %></td>
                <td>
                    <a style="font-size:14px" href="${pageContext.request.contextPath }/admin/changebook.jsp?book_id=<%=book.getBook_id() %>">修改</a>|
                    <a style="font-size:14px" href="${pageContext.request.contextPath }/DeleteBook?book_id=<%=book.getBook_id() %>">删除</a>
                </td>
            </tr>
            <%
        };
        %>
        </table>
    </div>
</div>
<!-- 调用底部页面 -->
<div style="width:100%;height:60px;float:left">
<jsp:include page="/admin/foot.jsp"></jsp:include>
</div>
</body>
<%} %>
</html>

效果图


3.userManager.jsp

管理用户也比较简单,就跟管理图书差不多一个样就行了。我抄我自己!(这样保持比较一致的风格也好。)

<%@page import="cn.edu.bdu.mc.daos.impls.UserDaoImpl"%>
<%@page import="cn.edu.bdu.mc.daos.UserDao"%>
<%@page import="cn.edu.bdu.mc.beans.User"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>用户管理</title>

</head>
<%
    if(request.getSession().getAttribute("root")==null){
        response.sendRedirect(request.getContextPath()+"/client/login.jsp");
    }else{
        UserDao userDao = new UserDaoImpl();
        List<User>users = userDao.findNormalUser();
%>
<body style="background-color:#bbb;width:1400px;margin:0 auto">
<!-- 调用头部页面 -->
<div style="width:100%;height:100px;float:left">
<jsp:include page="/admin/head.jsp"></jsp:include>
</div>
<!-- 通用内容体大小 -->
<div class="pre-scrollable" style="width:70%;height:720px;float:left;margin-left:15%;overflow:auto">
    <div class="panel panel-info">
        <div class="panel-heading">
            <h3 class="panel-title">用户管理</h3>
        </div>
        <table class="table">
            <tr>
                <th>用户名</th>
                <th>密码</th>
                <th>邮箱</th>
                <th>性别</th>
                <th>描述</th>
                <th>操作</th>
            </tr>
        <%
        for(User user:users){
        %>
            <tr>
                <td><%=user.getUsername() %></td>
                <td><%=user.getPassword() %></td>
                <td><%=user.getEmail() %></td>
                <td><%=user.getGender() %></td>
                <td><%=user.getDescribtion() %></td>
                <td>
                    <a style="font-size:14px" href="${pageContext.request.contextPath }/ResetPassword?user_id=<%=user.getUser_id() %>">重置密码</a>|
                    <a style="font-size:14px" href="${pageContext.request.contextPath }/DeleteUser?user_id=<%=user.getUser_id() %>">删除</a>
                </td>
            </tr>
            <%
        };
        %>
        </table>
    </div>
</div>
<!-- 调用底部页面 -->
<div style="width:100%;height:60px;float:left">
<jsp:include page="/admin/foot.jsp"></jsp:include>
</div>
</body>
<%} %>
</html>

效果图

4.error404.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<title>错误404</title>
</head>
<body style="background-color:#bbb;width:1400px;margin:0 auto">
<!-- 调用头部页面 -->
<div style="width:100%;height:100px;float:left">
<jsp:include page="/client/head.jsp"></jsp:include>
</div>
<!-- 通用内容体大小 -->
<div style="width:70%;height:720px;float:left;margin-left:15%;">
    <img alt="这是404页面" src="${pageContext.request.contextPath }/client/img/404.jpg" width="100%" height="100%"/>
</div>
<!-- 调用底部页面 -->
<div style="width:100%;height:60px;float:left">
<jsp:include page="/client/foot.jsp"></jsp:include>
</div>
</body>
</html>

效果图

5.error500.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<title>错误500</title>
</head>
<body style="background-color:#bbb;width:1400px;margin:0 auto">
<!-- 调用头部页面 -->
<div style="width:100%;height:100px;float:left">
<jsp:include page="/client/head.jsp"></jsp:include>
</div>
<!-- 通用内容体大小 -->
<div style="width:70%;height:720px;float:left;margin-left:15%;">
    <img alt="这是500页面" src="${pageContext.request.contextPath }/client/img/500.jpg" width="100%" height="100%"/>
</div>
<!-- 调用底部页面 -->
<div style="width:100%;height:60px;float:left">
<jsp:include page="/client/foot.jsp"></jsp:include>
</div>
</body>
</html>

效果图

6.errorelse.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<title>其他错误</title>
</head>
<body style="background-color:#bbb;width:1400px;margin:0 auto">
<!-- 调用头部页面 -->
<div style="width:100%;height:100px;float:left">
<jsp:include page="/client/head.jsp"></jsp:include>
</div>
<!-- 通用内容体大小 -->
<center style="color:red;font-size:30px">
我也不知道你遇到了什么错误。。<br/>
I also don't know what you meet...
</center>
<!-- 调用底部页面 -->
<div style="width:100%;height:60px;float:left">
<jsp:include page="/client/foot.jsp"></jsp:include>
</div>
</body>
</html>

效果图

7.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>bookstore</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <error-page>
    <error-code>404</error-code>
    <location>/error404.jsp</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/error500.jsp</location>
</error-page>
<error-page>
   <exception-type>java.lang.Exception</exception-type>
   <location>/errorelse.jsp</location>
</error-page>
</web-app>

8.addFenLeiServlet

package cn.edu.bdu.mc.servlets;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.bdu.mc.daos.BookDao;
import cn.edu.bdu.mc.daos.impls.BookDaoImpl;

/**
 * Servlet implementation class AddFenLeiServlet
 */
@WebServlet("/AddFenLei")
public class AddFenLeiServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddFenLeiServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @SuppressWarnings("deprecation")
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String fenlei_name = request.getParameter("fenlei_name");
        String fenlei_table = request.getParameter("feilei_table");
        BookDao bookDao = new BookDaoImpl();
        try {
            bookDao.addFenLei(fenlei_table, fenlei_name);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String realPath = request.getRealPath("client\\"+fenlei_table);
        File file = new File(realPath);
        file.mkdir();
        String htmlIndex="<%@page import=\"cn.edu.bdu.mc.services.impls.BookServiceImpl\"%>\r\n" +
                "<%@page import=\"cn.edu.bdu.mc.beans.Book\"%>\r\n" +
                "<%@page import=\"java.util.List\"%>\r\n" +
                "<%@ page language=\"java\" contentType=\"text/html; charset=utf-8\"\r\n" +
                "    pageEncoding=\"utf-8\"%>\r\n" +
                "<!DOCTYPE html>\r\n" +
                "<html>\r\n" +
                "<head>\r\n" +
                "<title>主页</title>\r\n" +
                "<style type=\"text/css\">\r\n" +
                "   .inc{\r\n" +
                "       float:left;\r\n" +
                "       margin-left:3%;\r\n" +
                "       margin-top:4%;\r\n" +
                "       width:16%;\r\n" +
                "       height:25%;\r\n" +
                "       background-color:rgba(160,128,255,0.8);\r\n" +
                "   }\r\n" +
                "</style>\r\n" +
                "<script type=\"text/javascript\" src=\"${pageContext.request.contextPath}/jquery-3.3.1/jquery-3.3.1.min.js\"></script>\r\n" +
                "<script type=\"text/javascript\">\r\n" +
                "$(function(){\r\n" +
                "       $(\"img\").click(function(){\r\n" +
                "           var book_id=$(this)[0].src.split(\"=\")[1];\r\n" +
                "           if(book_id!=0){\r\n" +
                "               $.post(\"../../FindPageById?book_id=\"+book_id,function(data){\r\n" +
                "                   window.location.href=data.split(\"/\")[1];\r\n" +
                "               });\r\n" +
                "           }\r\n" +
                "       });\r\n" +
                "});\r\n" +
                "</script>\r\n" +
                "</head>\r\n" +
                "<body style=\"background-color:#bbb;width:1400px;margin:0 auto\">\r\n" +
                "<!-- 调用头部页面 -->\r\n" +
                "<div style=\"width:100%;height:100px;float:left\">\r\n" +
                "<jsp:include page=\"/client/head.jsp\"></jsp:include>\r\n" +
                "</div>\r\n" +
                "<!-- 通用内容体大小 -->\r\n" +
                "<div style=\"width:70%;height:886px;float:left;margin-left:15%;\">\r\n" +
                "   <!-- 二级导航 -->\r\n" +
                "   <jsp:include page=\"/client/head2.jsp\"></jsp:include>  \r\n" +
                "   <img id=\"a1\">\r\n" +
                "   <!-- 通用界面 -->\r\n" +
                "   <div style=\"width:100%;height:800px;float:left;margin-top:2%;background-color:#ccc;\">\r\n" +
                "       <% List<Book>list = new BookServiceImpl().findBookByClazz(\""+fenlei_table+"\");\r\n" +
                "           int i=1;\r\n" +
                "           for(Book book:list){\r\n" +
                "               if(i>15){break;}%>\r\n" +
                "           <div class=\"inc\" <%if(i%5==1){ %>style=\"margin-left:4%\"<%} %>>\r\n" +
                "               <img alt=\"图书\" src=\"${pageContext.request.contextPath}/ShuImgById?book_id=<%=book.getBook_id() %>\" style=\"width:100%;height:100%;float:left;\"/>\r\n" +
                "           </div>\r\n" +
                "               <%\r\n" +
                "           };\r\n" +
                "       %>\r\n" +
                "   </div>\r\n" +
                "</div>\r\n" +
                "<!-- 调用底部页面 -->\r\n" +
                "<div style=\"width:100%;height:60px;float:left\">\r\n" +
                "<jsp:include page=\"/client/foot.jsp\"></jsp:include>\r\n" +
                "</div>\r\n" +
                "</body>\r\n" +
                "</html>";
        String htmlShu="<%@page import=\"cn.edu.bdu.mc.beans.FenLei\"%>\r\n" +
                "<%@page import=\"cn.edu.bdu.mc.daos.impls.FenLeiDaoImpl\"%>\r\n" +
                "<%@page import=\"cn.edu.bdu.mc.daos.FenLeiDao\"%>\r\n" +
                "<%@page import=\"cn.edu.bdu.mc.beans.User\"%>\r\n" +
                "<%@page import=\"cn.edu.bdu.mc.utils.CookieUtil\"%>\r\n" +
                "<%@page import=\"cn.edu.bdu.mc.services.impls.BookServiceImpl\"%>\r\n" +
                "<%@page import=\"cn.edu.bdu.mc.services.BookService\"%>\r\n" +
                "<%@page import=\"cn.edu.bdu.mc.beans.Book\"%>\r\n" +
                "<%@ page language=\"java\" contentType=\"text/html; charset=utf-8\"\r\n" +
                "    pageEncoding=\"utf-8\"%>\r\n" +
                "<%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\" %>\r\n" +
                "<!DOCTYPE html>\r\n" +
                "<html>\r\n" +
                "<head>\r\n" +
                "   <% \r\n" +
                "   BookService bookService = new BookServiceImpl();\r\n" +
                "   int er_id = Integer.parseInt(request.getParameter(\"er_id\"));\r\n" +
                "   Book book = bookService.findBookByClazzAndEr_id(\""+fenlei_table+"\",er_id);\r\n" +
                "   bookService.click(book.getBook_id());\r\n" +
                "   User user = (User)session.getAttribute(\"user\");\r\n" +
                "   if(user!=null){\r\n" +
                "       user.setBook_history(book.getBook_id()+\"#\"+user.getBook_history());\r\n" +
                "       if(user.getBook_history().split(\"#\").length>5){\r\n" +
                "           user.setBook_history(user.getBook_history().substring(0, user.getBook_history().lastIndexOf(\"#\")));\r\n" +
                "       }\r\n" +
                "   }\r\n" +
                "   %>\r\n" +
                "<title><%=book.getBook_name() %></title>\r\n" +
                "<style type=\"text/css\">\r\n" +
                "   .inc{\r\n" +
                "       float:left;\r\n" +
                "       margin-left:3%;\r\n" +
                "       margin-top:1%;\r\n" +
                "       width:16%;\r\n" +
                "       height:90%;\r\n" +
                "       background-color:rgba(160,128,255,0.8);\r\n" +
                "   }\r\n" +
                "</style>\r\n" +
                "<script type=\"text/javascript\" src=\"${pageContext.request.contextPath}/jquery-3.3.1/jquery-3.3.1.min.js\"></script>\r\n" +
                "<script type=\"text/javascript\" src=\"${pageContext.request.contextPath}/client/js/shu.js\"></script>\r\n" +
                "</head>\r\n" +
                "<body style=\"background-color:#bbb;width:1400px;margin:0 auto\">\r\n" +
                "<!-- 调用头部页面 -->\r\n" +
                "<div style=\"width:100%;height:100px;float:left\">\r\n" +
                "<jsp:include page=\"/client/head.jsp\"></jsp:include>\r\n" +
                "</div>\r\n" +
                "<!-- 通用内容体大小 -->\r\n" +
                "<div style=\"width:70%;height:886px;float:left;margin-left:15%;\">\r\n" +
                "   <!-- 二级导航 -->\r\n" +
                "   <jsp:include page=\"/client/head2.jsp\"></jsp:include>  \r\n" +
                "   <!-- 通用界面 -->\r\n" +
                "   <div style=\"width:100%;height:800px;float:left;margin-top:2%;background-color:#ccc;\">\r\n" +
                "       <div style=\"width:100%;height:48%;float:left;margin-top:2%;margin-left:2%;\">\r\n" +
                "           <div style=\"width:30%;height:100%;background-color:rgba(111,123,145,0.8);float:left\">\r\n" +
                "               <img alt=\"图书\" src=\"${pageContext.request.contextPath}/ShuImgById?book_id=<%=book.getBook_id() %>\" style=\"width:100%;\"/>\r\n" +
                "           </div>\r\n" +
                "           <div style=\"width:60%;margin-left:8%;height:100%;float:left\">\r\n" +
                "               <h2 style=\"margin-left:2%;float:left;width:94%\"><%=book.getBook_name() %></h2>\r\n" +
                "               <p style=\"margin-left:2%;float:left;width:94%;height:30%;\">详情:<%=book.getDescribtion() %><a style=\"margin-left:2%;\" href=\"./\">点击</a>查看更多同类好书!</p>\r\n" +
                "               <h2 style=\"margin-left:2%;margin-top:1%;float:left;width:94%;color:rgba(200,0,0,0.8);text-align:center;background-color:rgba(64,123,233,0.4);height:18%;line-height:200%;\">惊爆价:<%=book.getPrice() %>&nbsp;元&nbsp;&nbsp;&nbsp;&nbsp;\r\n" +
                "                   <font style=\"color:rgba(0,0,0,0.6);font-size:24px;\"><del>原价:<%double price = (int)(book.getPrice()*1.4)-0.01; %><%=price %>&nbsp;元</del></font>\r\n" +
                "               </h2>\r\n" +
                "               <font style=\"margin-left:2%;margin-top:1%;float:left;width:94%;font-size:16px;\">类别:<%=new FenLeiDaoImpl().findByTable(book.getClazz()).getFenlei_name() %></font>\r\n" +
                "               <font style=\"margin-left:2%;margin-top:1%;float:left;font-size:16px;\">点击量:<%=book.getClick_num() %></font>\r\n" +
                "               <font style=\"margin-left:2%;margin-top:1%;float:left;font-size:16px;\">购买量:<%=book.getBuy_num() %></font>\r\n" +
                "               <font style=\"margin-left:2%;margin-top:1%;float:left;font-size:16px;\">热度:<%=book.getRe_du() %></font>\r\n" +
                "               <font style=\"margin-left:2%;margin-top:1%;float:left;width:94%;font-size:16px;\">剩余数量:<%=book.getCount() %></font>\r\n" +
                "               <% if(request.getSession().getAttribute(\"user\")==null){ %>\r\n" +
                "                   <font style=\"margin-left:2%;margin-top:1%;float:left;\"><a href=\"${pageContext.request.contextPath}/client/login.jsp\">登录</a>后可购买书籍。</font>\r\n" +
                "               <% }else{ %>\r\n" +
                "                   <a style=\"margin-left:2%;margin-top:1%;float:left;\" href=\"${pageContext.request.contextPath}/AddIntoCart?book_id=<%=book.getBook_id() %>\">加入购物车</a>&nbsp;&nbsp;&nbsp;&nbsp;\r\n" +
                "                   <a style=\"margin-left:2%;margin-top:1%;float:left;\" href=\"${pageContext.request.contextPath}/NewOrder?book_id_list=<%=book.getBook_id() %>\">购买</a>\r\n" +
                "               <% } %>\r\n" +
                "           </div>\r\n" +
                "       </div>\r\n" +
                "       <div style=\"width:96%;height:40%;float:left;margin-top:2%;margin-left:2%;\">\r\n" +
                "           <div style=\"width:100%;height:15%;text-align:center;line-height:50px;background-color:rgba(85,107,47,0.8);float:left\">\r\n" +
                "               <font color=\"#ddd\" style=\"font-size:20px;\">为您推荐热门书籍</font>\r\n" +
                "           </div>\r\n" +
                "           <div style=\"width:100%;height:85%;text-align:center;line-height:45px;background-color:rgba(85,139,84,0.8);float:left\">\r\n" +
                "               <div class=\"inc\" style=\"margin-left:4%\">\r\n" +
                "                   <img alt=\"图书\" src=\"${pageContext.request.contextPath}/XinShuImg?shu=1\" style=\"width:100%;height:100%\" id=\"re1\"/>\r\n" +
                "               </div>\r\n" +
                "               <div class=\"inc\">\r\n" +
                "                   <img alt=\"图书\" src=\"${pageContext.request.contextPath}/XinShuImg?shu=2\" style=\"width:100%;height:100%\" id=\"re2\"/>\r\n" +
                "               </div>\r\n" +
                "               <div class=\"inc\">\r\n" +
                "                   <img alt=\"图书\" src=\"${pageContext.request.contextPath}/XinShuImg?shu=3\" style=\"width:100%;height:100%\" id=\"re3\"/>\r\n" +
                "               </div>\r\n" +
                "               <div class=\"inc\">\r\n" +
                "                   <img alt=\"图书\" src=\"${pageContext.request.contextPath}/XinShuImg?shu=4\" style=\"width:100%;height:100%\" id=\"re4\"/>\r\n" +
                "               </div>\r\n" +
                "               <div class=\"inc\">\r\n" +
                "                   <img alt=\"图书\" src=\"${pageContext.request.contextPath}/XinShuImg?shu=5\" style=\"width:100%;height:100%\" id=\"re5\"/>\r\n" +
                "               </div>\r\n" +
                "           </div>\r\n" +
                "       </div>\r\n" +
                "   </div>\r\n" +
                "</div>\r\n" +
                "<!-- 调用底部页面 -->\r\n" +
                "<div style=\"width:100%;height:60px;float:left\">\r\n" +
                "<jsp:include page=\"/client/foot.jsp\"></jsp:include>\r\n" +
                "</div>\r\n" +
                "</body>\r\n" +
                "</html>";
        BufferedWriter bw=new BufferedWriter(new FileWriter(realPath+"\\index.jsp"));
        bw.write(htmlIndex);
        BufferedWriter bw1 = new BufferedWriter(new FileWriter(realPath+"\\shu.jsp"));
        bw1.write(htmlShu);
        bw.close();
        bw1.close();
        realPath = "D:\\zhang-java\\WebContent\\client\\"+fenlei_table;
        file = new File(realPath);
        file.mkdir();
        BufferedWriter bw2=new BufferedWriter(new FileWriter(realPath+"\\index.jsp"));
        bw2.write(htmlIndex);
        BufferedWriter bw3 = new BufferedWriter(new FileWriter(realPath+"\\shu.jsp"));
        bw3.write(htmlShu);
        bw2.close();
        bw3.close();
        response.sendRedirect(request.getContextPath()+"/admin/index.jsp");
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

9.bookDao里的addFenLei

@Override
    public void addFenLei(String fenleiming,String fenlei_name) throws SQLException {
        // TODO Auto-generated method stub
        String sql = "CREATE TABLE `"+fenleiming+"` (\r\n" +
                "  `book_name` varchar(40) NOT NULL,\r\n" +
                "  `price` double NOT NULL,\r\n" +
                "  `describtion` varchar(200) DEFAULT NULL,\r\n" +
                "  `clazz` varchar(40) NOT NULL,\r\n" +
                "  `second_id` int(11) NOT NULL AUTO_INCREMENT,\r\n" +
                "  `book_img` blob,\r\n" +
                "  `click_num` int(11) NOT NULL,\r\n" +
                "  `buy_num` int(9) NOT NULL,\r\n" +
                "  `re_du` int(12) DEFAULT NULL,\r\n" +
                "  `count` int(6) NOT NULL,\r\n" +
                "  `is_new` int(1) NOT NULL,\r\n" +
                "  `insert_date` date NOT NULL,\r\n" +
                "  `book_id` int(11) DEFAULT NULL,\r\n" +
                "  PRIMARY KEY (`second_id`)\r\n" +
                ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
        String sql1="CREATE TRIGGER `"+fenleiming+"_insert` AFTER INSERT ON `"+fenleiming+"` FOR EACH ROW begin\r\n" +
                "   insert into book(book_name,price,describtion,clazz,second_id,click_num,buy_num,count,is_new,insert_date,book_img) values(NEW.book_name,NEW.price,NEW.describtion,NEW.clazz,NEW.second_id,0,0,NEW.count,1,NEW.insert_date,new.book_img);\r\n" +
                "end\r\n" +
                ";;\r\n" ;
        String sql2="CREATE TRIGGER `"+fenleiming+"1_update` BEFORE UPDATE ON `"+fenleiming+"` FOR EACH ROW begin\r\n" +
                "   set new.re_du = new.click_num+new.buy_num*100;\r\n" +
                "   end\r\n" +
                ";;\r\n" ;
        String sql3="CREATE TRIGGER `"+fenleiming+"_update` AFTER UPDATE ON `"+fenleiming+"` FOR EACH ROW begin\r\n" +
                "   update book set book.re_du = NEW.click_num + NEW.buy_num * 100,book.click_num = NEW.click_num,book.buy_num = NEW.buy_num,book.book_img=new.book_img where clazz = new.clazz and second_id = new.second_id;\r\n" +
                "end\r\n" +
                ";;\r\n" ;
        String sql4="insert into fenlei(fenlei_name,fenlei_table) values('"+fenlei_name+"','"+fenleiming+"')";
        Connection connection = JDBCUtil.getConn();
        Statement statement = connection.createStatement();
        statement.addBatch(sql);
        statement.addBatch(sql1);
        statement.addBatch(sql2);
        statement.addBatch(sql3);
        statement.addBatch(sql4);
        statement.executeBatch();
    }

总结

可能还有忘记了的改动。emmm我将在github上上传我的完整代码。

github页面

bookstoreZhang

原文地址:https://www.cnblogs.com/zhangA/p/11087245.html

时间: 2024-10-08 15:19:51

大项目之网上书城(十二)——完成啦的相关文章

大项目之网上书城(二)——主页(上)

目录 大项目之网上书城(二)--主页(上) 1.主页 代码 效果图 2.head2.jsp 代码 效果图 3.二级页面的empty.jsp 代码 效果图 总结 WebContent图 大项目之网上书城(二)--主页(上) 实在是太复杂啦,弄了半天才调出来一个壳子.明天再继续吧... 1.主页 代码 值得一提的是,我把所以的路径都改成用${pageContext}来获取的了,这样就可以方便我在不同的地方复制粘贴同样的代码,能有同样的功效了.(甚至字体的url都改了23333) <%@ page l

大项目之网上书城(六)——个人页面和书页面Demo

目录 大项目之网上书城(六)--个人页面和书页面Demo 主要改动 1.user.jsp 代码 效果图 user.js 代码 3.shu.jsp 代码 效果图 4.其他小改动 LoginServlet LogoutServlet BookService XinShuMingServlet 5.新增 FindPageByIdServlet ShuImgByIdServlet 总结 大项目之网上书城(六)--个人页面和书页面Demo 主要改动 今天时间依旧不是很多,,主要是今天思路不够丰富.勉强给个

大项目之网上书城(九)——订单Demo

目录 大项目之网上书城(九)--订单Demo 主要改动 1.OrderServiceImpl 代码 2.OrderDaoImpl 代码 3.OrderitemDaoImpl 代码 4.orderitem_insert触发器 代码 5.DelOrderServlet 代码 6.NewOrderServlet 代码 7.PayForServlet 代码 8.shouhuo.jsp 代码 效果图 9.order.jsp 代码 效果图 总结 大项目之网上书城(九)--订单Demo 主要改动 加了创建订单

(转载)Android项目实战(三十二):圆角对话框Dialog

Android项目实战(三十二):圆角对话框Dialog 前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对话框的"确定"按钮 难点:1.对话框边框圆角显示 2.考虑到提示文本字数不确定,在不影响美观的情况下,需要在一行内显示提示的文字信息   3.设置对话框的宽和高 技术储备: 1.安卓开发_使用AlertDialog实现对话框    知道AlertDialog有setView(view) ,Dia

Android项目实战(三十二):圆角对话框Dialog

原文:Android项目实战(三十二):圆角对话框Dialog 前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对话框的"确定"按钮 难点:1.对话框边框圆角显示 2.考虑到提示文本字数不确定,在不影响美观的情况下,需要在一行内显示提示的文字信息   3.设置对话框的宽和高 技术储备: 1.安卓开发_使用AlertDialog实现对话框    知道AlertDialog有setView(view) ,

Android项目实战(四十二):启动页优化,去除短暂白屏或黑屏

原文:Android项目实战(四十二):启动页优化,去除短暂白屏或黑屏 大家会发现一个空项目,从手机桌面打开app是秒启动.但是对于自己开发的项目,有时会发现打开app的时候,会有短暂的1秒--2秒的白屏或者黑屏,然后才进入到程序界面. 个人理解为我们自己实现的Application文件里面做了较多的初始化操作,当这些初始化操作完成后才进入到第一个Activity,这段初始化的时间因为没有界面,应用便会因为主题的类别而显示白屏或者黑屏. 构成白屏/黑屏的原因代码如下: /*** @author

【无私分享:ASP.NET CORE 项目实战(第十二章)】添加对SqlServer、MySql、Oracle的支持

目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 增加对多数据库的支持,并不是意味着同时对多种数据库操作,当然,后面,我们会尝试同时对多种数据库操作,这可能需要多个上下文,暂且不论.分布式数据库,我们采用的是阿里云的Mycat,这个后面会更新出来.我们今天的场景是:我们的项目可能是在windows上开发的使用的是SqlServer,我们要发布到linux上,SqlServer 2017 据说是支持liunx的,但是还没出... 当然不是说 SqlServer 就不能装在l

自然语言交流系统 phxnet团队 创新实训 项目博客 (十二)

关于情感词典的学习总结: 情感倾向可认为是主体对某一客体主观存在的内心喜恶,内在评价的一种倾向.它由两个方面来衡量:一个情感倾向方向,一个是情感倾向度. 情感倾向方向也称为情感极性.在微博中,可以理解为用户对某客体表达自身观点所持的态度是支持.反对.中立,即通常所指的正面情感.负面情感.中性情感.例如"赞美"与"表扬"同为褒义词,表达正面情感,而"龌龊"与"丑陋"就是贬义词,表达负面情感. 情感倾向度是指主体对客体表达正面情感

项目2——网上书城项目

这个项目是帮舍友做的毕设项目,舍友是个作家,写小说的,想做一个管理小说的系统,我就帮代劳了,如果做出来他看不上再花钱找别人那就不该我事了哈哈,我尽力给做的好一点吧,舍友需求还是挺简单的 首先进行需求分析 前台 1.用户模块: 注册 激活 登录 退出 2.分类模块: 查看所有分类 3.图书模块 查询所有图书 按分类查询图书 查询图书详细(按id查询) 4.购物车模块: 添加购物车条目 清空所有条目 删除指定条目 我的购物车(按用户查询购物车) 5.订单模块 生成订单 我的订单(按用户查询订单) 按