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


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

    主要改动

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

    新增代码

    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;1400px;margin:0 auto">
    <!-- 调用头部页面 -->
    <div style="100%;height:100px;float:left">
    <jsp:include page="/admin/head.jsp"></jsp:include>
    </div>
    <!-- 通用内容体大小 -->
    <div style="70%;height:720px;float:left;margin-left:15%;">
    <!-- 好看的图 -->
    	<div style="55%;height:100%;float:left;margin-top:10%;">
    		<img alt="书架" src="${pageContext.request.contextPath }/client/img/bookshelf.jpg" style="90%;">
    	</div>
    	<!-- 添加界面 -->
    	<div style="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="100%;float:left"/>
    			</div>
    		</div>
    		</form>
    	</div>
    </div>
    <!-- 调用底部页面 -->
    <div style="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;1400px;margin:0 auto">
    <!-- 调用头部页面 -->
    <div style="100%;height:100px;float:left">
    <jsp:include page="/admin/head.jsp"></jsp:include>
    </div>
    <!-- 通用内容体大小 -->
    <div class="pre-scrollable" style="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="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;1400px;margin:0 auto">
    <!-- 调用头部页面 -->
    <div style="100%;height:100px;float:left">
    <jsp:include page="/admin/head.jsp"></jsp:include>
    </div>
    <!-- 通用内容体大小 -->
    <div class="pre-scrollable" style="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="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;1400px;margin:0 auto">
    <!-- 调用头部页面 -->
    <div style="100%;height:100px;float:left">
    <jsp:include page="/client/head.jsp"></jsp:include>
    </div>
    <!-- 通用内容体大小 -->
    <div style="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="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;1400px;margin:0 auto">
    <!-- 调用头部页面 -->
    <div style="100%;height:100px;float:left">
    <jsp:include page="/client/head.jsp"></jsp:include>
    </div>
    <!-- 通用内容体大小 -->
    <div style="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="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;1400px;margin:0 auto">
    <!-- 调用头部页面 -->
    <div style="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="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"%>
    " + 
    				"<%@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>
    " + 
    				"<style type="text/css">
    " + 
    				"	.inc{
    " + 
    				"		float:left;
    " + 
    				"		margin-left:3%;
    " + 
    				"		margin-top:4%;
    " + 
    				"		16%;
    " + 
    				"		height:25%;
    " + 
    				"		background-color:rgba(160,128,255,0.8);
    " + 
    				"	}
    " + 
    				"</style>
    " + 
    				"<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-3.3.1/jquery-3.3.1.min.js"></script>
    " + 
    				"<script type="text/javascript">
    " + 
    				"$(function(){
    " + 
    				"		$("img").click(function(){
    " + 
    				"			var book_id=$(this)[0].src.split("=")[1];
    " + 
    				"			if(book_id!=0){
    " + 
    				"				$.post("../../FindPageById?book_id="+book_id,function(data){
    " + 
    				"					window.location.href=data.split("/")[1];
    " + 
    				"				});
    " + 
    				"			}
    " + 
    				"		});
    " + 
    				"});
    " + 
    				"</script>
    " + 
    				"</head>
    " + 
    				"<body style="background-color:#bbb;1400px;margin:0 auto">
    " + 
    				"<!-- 调用头部页面 -->
    " + 
    				"<div style="100%;height:100px;float:left">
    " + 
    				"<jsp:include page="/client/head.jsp"></jsp:include>
    " + 
    				"</div>
    " + 
    				"<!-- 通用内容体大小 -->
    " + 
    				"<div style="70%;height:886px;float:left;margin-left:15%;">
    " + 
    				"	<!-- 二级导航 -->
    " + 
    				"	<jsp:include page="/client/head2.jsp"></jsp:include>	
    " + 
    				"	<img id="a1">
    " + 
    				"	<!-- 通用界面 -->
    " + 
    				"	<div style="100%;height:800px;float:left;margin-top:2%;background-color:#ccc;">
    " + 
    				"		<% List<Book>list = new BookServiceImpl().findBookByClazz(""+fenlei_table+"");
    " + 
    				"			int i=1;
    " + 
    				"			for(Book book:list){
    " + 
    				"				if(i>15){break;}%>
    " + 
    				"			<div class="inc" <%if(i%5==1){ %>style="margin-left:4%"<%} %>>
    " + 
    				"				<img alt="图书" src="${pageContext.request.contextPath}/ShuImgById?book_id=<%=book.getBook_id() %>" style="100%;height:100%;float:left;"/>
    " + 
    				"			</div>
    " + 
    				"				<%
    " + 
    				"			};
    " + 
    				"		%>
    " + 
    				"	</div>
    " + 
    				"</div>
    " + 
    				"<!-- 调用底部页面 -->
    " + 
    				"<div style="100%;height:60px;float:left">
    " + 
    				"<jsp:include page="/client/foot.jsp"></jsp:include>
    " + 
    				"</div>
    " + 
    				"</body>
    " + 
    				"</html>";
    		String htmlShu="<%@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.beans.User"%>
    " + 
    				"<%@page import="cn.edu.bdu.mc.utils.CookieUtil"%>
    " + 
    				"<%@page import="cn.edu.bdu.mc.services.impls.BookServiceImpl"%>
    " + 
    				"<%@page import="cn.edu.bdu.mc.services.BookService"%>
    " + 
    				"<%@page import="cn.edu.bdu.mc.beans.Book"%>
    " + 
    				"<%@ page language="java" contentType="text/html; charset=utf-8"
    " + 
    				"    pageEncoding="utf-8"%>
    " + 
    				"<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    " + 
    				"<!DOCTYPE html>
    " + 
    				"<html>
    " + 
    				"<head>
    " + 
    				"	<% 
    " + 
    				"	BookService bookService = new BookServiceImpl();
    " + 
    				"	int er_id = Integer.parseInt(request.getParameter("er_id"));
    " + 
    				"	Book book = bookService.findBookByClazzAndEr_id(""+fenlei_table+"",er_id);
    " + 
    				"	bookService.click(book.getBook_id());
    " + 
    				"	User user = (User)session.getAttribute("user");
    " + 
    				"	if(user!=null){
    " + 
    				"		user.setBook_history(book.getBook_id()+"#"+user.getBook_history());
    " + 
    				"		if(user.getBook_history().split("#").length>5){
    " + 
    				"			user.setBook_history(user.getBook_history().substring(0, user.getBook_history().lastIndexOf("#")));
    " + 
    				"		}
    " + 
    				"	}
    " + 
    				"	%>
    " + 
    				"<title><%=book.getBook_name() %></title>
    " + 
    				"<style type="text/css">
    " + 
    				"	.inc{
    " + 
    				"		float:left;
    " + 
    				"		margin-left:3%;
    " + 
    				"		margin-top:1%;
    " + 
    				"		16%;
    " + 
    				"		height:90%;
    " + 
    				"		background-color:rgba(160,128,255,0.8);
    " + 
    				"	}
    " + 
    				"</style>
    " + 
    				"<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-3.3.1/jquery-3.3.1.min.js"></script>
    " + 
    				"<script type="text/javascript" src="${pageContext.request.contextPath}/client/js/shu.js"></script>
    " + 
    				"</head>
    " + 
    				"<body style="background-color:#bbb;1400px;margin:0 auto">
    " + 
    				"<!-- 调用头部页面 -->
    " + 
    				"<div style="100%;height:100px;float:left">
    " + 
    				"<jsp:include page="/client/head.jsp"></jsp:include>
    " + 
    				"</div>
    " + 
    				"<!-- 通用内容体大小 -->
    " + 
    				"<div style="70%;height:886px;float:left;margin-left:15%;">
    " + 
    				"	<!-- 二级导航 -->
    " + 
    				"	<jsp:include page="/client/head2.jsp"></jsp:include>	
    " + 
    				"	<!-- 通用界面 -->
    " + 
    				"	<div style="100%;height:800px;float:left;margin-top:2%;background-color:#ccc;">
    " + 
    				"		<div style="100%;height:48%;float:left;margin-top:2%;margin-left:2%;">
    " + 
    				"			<div style="30%;height:100%;background-color:rgba(111,123,145,0.8);float:left">
    " + 
    				"				<img alt="图书" src="${pageContext.request.contextPath}/ShuImgById?book_id=<%=book.getBook_id() %>" style="100%;"/>
    " + 
    				"			</div>
    " + 
    				"			<div style="60%;margin-left:8%;height:100%;float:left">
    " + 
    				"				<h2 style="margin-left:2%;float:left;94%"><%=book.getBook_name() %></h2>
    " + 
    				"				<p style="margin-left:2%;float:left;94%;height:30%;">详情:<%=book.getDescribtion() %><a style="margin-left:2%;" href="./">点击</a>查看更多同类好书!</p>
    " + 
    				"				<h2 style="margin-left:2%;margin-top:1%;float:left;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;
    " + 
    				"					<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>
    " + 
    				"				</h2>
    " + 
    				"				<font style="margin-left:2%;margin-top:1%;float:left;94%;font-size:16px;">类别:<%=new FenLeiDaoImpl().findByTable(book.getClazz()).getFenlei_name() %></font>
    " + 
    				"				<font style="margin-left:2%;margin-top:1%;float:left;font-size:16px;">点击量:<%=book.getClick_num() %></font>
    " + 
    				"				<font style="margin-left:2%;margin-top:1%;float:left;font-size:16px;">购买量:<%=book.getBuy_num() %></font>
    " + 
    				"				<font style="margin-left:2%;margin-top:1%;float:left;font-size:16px;">热度:<%=book.getRe_du() %></font>
    " + 
    				"				<font style="margin-left:2%;margin-top:1%;float:left;94%;font-size:16px;">剩余数量:<%=book.getCount() %></font>
    " + 
    				"				<% if(request.getSession().getAttribute("user")==null){ %>
    " + 
    				"					<font style="margin-left:2%;margin-top:1%;float:left;"><a href="${pageContext.request.contextPath}/client/login.jsp">登录</a>后可购买书籍。</font>
    " + 
    				"				<% }else{ %>
    " + 
    				"					<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;
    " + 
    				"					<a style="margin-left:2%;margin-top:1%;float:left;" href="${pageContext.request.contextPath}/NewOrder?book_id_list=<%=book.getBook_id() %>">购买</a>
    " + 
    				"				<% } %>
    " + 
    				"			</div>
    " + 
    				"		</div>
    " + 
    				"		<div style="96%;height:40%;float:left;margin-top:2%;margin-left:2%;">
    " + 
    				"			<div style="100%;height:15%;text-align:center;line-height:50px;background-color:rgba(85,107,47,0.8);float:left">
    " + 
    				"				<font color="#ddd" style="font-size:20px;">为您推荐热门书籍</font>
    " + 
    				"			</div>
    " + 
    				"			<div style="100%;height:85%;text-align:center;line-height:45px;background-color:rgba(85,139,84,0.8);float:left">
    " + 
    				"				<div class="inc" style="margin-left:4%">
    " + 
    				"					<img alt="图书" src="${pageContext.request.contextPath}/XinShuImg?shu=1" style="100%;height:100%" id="re1"/>
    " + 
    				"				</div>
    " + 
    				"				<div class="inc">
    " + 
    				"					<img alt="图书" src="${pageContext.request.contextPath}/XinShuImg?shu=2" style="100%;height:100%" id="re2"/>
    " + 
    				"				</div>
    " + 
    				"				<div class="inc">
    " + 
    				"					<img alt="图书" src="${pageContext.request.contextPath}/XinShuImg?shu=3" style="100%;height:100%" id="re3"/>
    " + 
    				"				</div>
    " + 
    				"				<div class="inc">
    " + 
    				"					<img alt="图书" src="${pageContext.request.contextPath}/XinShuImg?shu=4" style="100%;height:100%" id="re4"/>
    " + 
    				"				</div>
    " + 
    				"				<div class="inc">
    " + 
    				"					<img alt="图书" src="${pageContext.request.contextPath}/XinShuImg?shu=5" style="100%;height:100%" id="re5"/>
    " + 
    				"				</div>
    " + 
    				"			</div>
    " + 
    				"		</div>
    " + 
    				"	</div>
    " + 
    				"</div>
    " + 
    				"<!-- 调用底部页面 -->
    " + 
    				"<div style="100%;height:60px;float:left">
    " + 
    				"<jsp:include page="/client/foot.jsp"></jsp:include>
    " + 
    				"</div>
    " + 
    				"</body>
    " + 
    				"</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+"` (
    " + 
    				"  `book_name` varchar(40) NOT NULL,
    " + 
    				"  `price` double NOT NULL,
    " + 
    				"  `describtion` varchar(200) DEFAULT NULL,
    " + 
    				"  `clazz` varchar(40) NOT NULL,
    " + 
    				"  `second_id` int(11) NOT NULL AUTO_INCREMENT,
    " + 
    				"  `book_img` blob,
    " + 
    				"  `click_num` int(11) NOT NULL,
    " + 
    				"  `buy_num` int(9) NOT NULL,
    " + 
    				"  `re_du` int(12) DEFAULT NULL,
    " + 
    				"  `count` int(6) NOT NULL,
    " + 
    				"  `is_new` int(1) NOT NULL,
    " + 
    				"  `insert_date` date NOT NULL,
    " + 
    				"  `book_id` int(11) DEFAULT NULL,
    " + 
    				"  PRIMARY KEY (`second_id`)
    " + 
    				") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
    		String sql1="CREATE TRIGGER `"+fenleiming+"_insert` AFTER INSERT ON `"+fenleiming+"` FOR EACH ROW begin
    " + 
    				"	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);
    " + 
    				"end
    " + 
    				";;
    " ;
    		String sql2="CREATE TRIGGER `"+fenleiming+"1_update` BEFORE UPDATE ON `"+fenleiming+"` FOR EACH ROW begin
    " + 
    				"	set new.re_du = new.click_num+new.buy_num*100;
    " + 
    				"	end
    " + 
    				";;
    " ;
    		String sql3="CREATE TRIGGER `"+fenleiming+"_update` AFTER UPDATE ON `"+fenleiming+"` FOR EACH ROW begin
    " + 
    				"	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;
    " + 
    				"end
    " + 
    				";;
    " ;
    		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

  • 相关阅读:
    仿百度排列图片预览插件-Simple Lightbox
    vue2.0移动端自定义性别选择提示框
    微信小程序踩坑记
    网页里如何使用js禁用F12事件
    使用 html2canvas 实现浏览器截图
    h5、jq 移动端评论点攒功能
    js 数字递增特效 仿支付宝我的财富 HTML5
    aos.js超赞页面滚动元素动画jQuery动画库
    简洁AngularJS框架后台管理系统bootstrap后台模板
    Ionic 的 ng-class 在聊天功能上面的巧妙运用
  • 原文地址:https://www.cnblogs.com/zhangA/p/11087245.html
Copyright © 2020-2023  润新知