目錄javascript
管理員添加分類,管理圖書,管理用戶。以及往數據庫裏填了幾十本書。添加了錯誤頁面。css
由於以前給每一個分類都建了表,並且每一個表都有本身的文件夾。因而,添加分類好麻煩啊。具體見servlethtml
<%@ 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>
有點趕,就只簡單寫了個分類,沒有分頁,用加滾動條混過去吧。。java
<%@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() %> 元</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>
管理用戶也比較簡單,就跟管理圖書差很少一個樣就好了。我抄我本身!(這樣保持比較一致的風格也好。)jquery
<%@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>
<%@ 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>
<%@ 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>
<%@ 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>
<?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>
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() %> 元 \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 %> 元</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> \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); } }
@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上上傳個人完整代碼。git