├── .classpath ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.jdt.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container └── org.eclipse.wst.jsdt.ui.superType.name ├── README.md ├── WebRoot ├── META-INF │ └── MANIFEST.MF ├── WEB-INF │ ├── classes │ │ ├── c3p0-config.xml │ │ └── cn │ │ │ └── tf │ │ │ ├── Test │ │ │ └── TestCon.class │ │ │ ├── bean │ │ │ ├── Cart.class │ │ │ └── CartItem.class │ │ │ ├── commons │ │ │ └── Page.class │ │ │ ├── controller │ │ │ ├── ClientServlet.class │ │ │ ├── LoginServlet.class │ │ │ ├── ManageServlet.class │ │ │ ├── PayServlet.class │ │ │ └── ResponsePayServlet.class │ │ │ ├── dao │ │ │ ├── BookDao.class │ │ │ ├── CategoryDao.class │ │ │ ├── CustomerDao.class │ │ │ ├── OrderDao.class │ │ │ ├── PrivilegeDao.class │ │ │ └── impl │ │ │ │ ├── BookDaoImpl.class │ │ │ │ ├── CategoryDaoImpl.class │ │ │ │ ├── CustomerDaoImpl.class │ │ │ │ ├── OrderDaoImpl.class │ │ │ │ └── PrivilegeDaoImpl.class │ │ │ ├── domain │ │ │ ├── Book.class │ │ │ ├── Category.class │ │ │ ├── Customer.class │ │ │ ├── Function.class │ │ │ ├── Order.class │ │ │ ├── OrderItem.class │ │ │ ├── Role.class │ │ │ └── User.class │ │ │ ├── filter │ │ │ ├── CharseEncodingFilter.class │ │ │ ├── GetHttpServletRequest.class │ │ │ └── PrivilegeFilter.class │ │ │ ├── service │ │ │ ├── BusinessService.class │ │ │ ├── PrivilegeService.class │ │ │ └── impl │ │ │ │ ├── BusinessServiceImpl.class │ │ │ │ └── PrivilegeServiceImpl.class │ │ │ └── utils │ │ │ ├── C3P0Util.class │ │ │ ├── Constant.class │ │ │ ├── OrderNumUtil.class │ │ │ ├── PaymentUtil.class │ │ │ ├── SendMailThread.class │ │ │ └── WebUtil.class │ ├── lib │ │ ├── c3p0-0.9.1.2.jar │ │ ├── commons-beanutils-1.8.3.jar │ │ ├── commons-dbutils-1.4.jar │ │ ├── commons-fileupload-1.2.2.jar │ │ ├── commons-io-2.2.jar │ │ ├── commons-logging-1.1.1.jar │ │ ├── mail.jar │ │ └── mysql-connector-java-5.0.8-bin.jar │ └── web.xml ├── commons │ └── page.jsp ├── css │ └── main.css ├── header.jsp ├── index.jsp ├── js │ ├── jquery-1.11.3.js │ └── util.js ├── listBooks.jsp ├── listOrders.jsp ├── login.jsp ├── manage │ ├── addBook.jsp │ ├── addCategory.jsp │ ├── header.jsp │ ├── index.jsp │ ├── listBooks.jsp │ ├── listCategories.jsp │ └── message.jsp ├── message.jsp ├── passport │ └── login.jsp ├── pay.jsp ├── regist.jsp ├── showCart.jsp └── sure.jsp ├── db.sql └── src ├── c3p0-config.xml └── cn └── tf ├── Test └── TestCon.java ├── bean ├── Cart.java └── CartItem.java ├── commons └── Page.java ├── controller ├── ClientServlet.java ├── LoginServlet.java ├── ManageServlet.java ├── PayServlet.java └── ResponsePayServlet.java ├── dao ├── BookDao.java ├── CategoryDao.java ├── CustomerDao.java ├── OrderDao.java ├── PrivilegeDao.java └── impl │ ├── BookDaoImpl.java │ ├── CategoryDaoImpl.java │ ├── CustomerDaoImpl.java │ ├── OrderDaoImpl.java │ └── PrivilegeDaoImpl.java ├── domain ├── Book.java ├── Category.java ├── Customer.java ├── Function.java ├── Order.java ├── OrderItem.java ├── Role.java └── User.java ├── filter ├── CharseEncodingFilter.java └── PrivilegeFilter.java ├── service ├── BusinessService.java ├── PrivilegeService.java └── impl │ ├── BusinessServiceImpl.java │ └── PrivilegeServiceImpl.java └── utils ├── C3P0Util.java ├── Constant.java ├── OrderNumUtil.java ├── PaymentUtil.java ├── SendMailThread.java └── WebUtil.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | BookStore 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator 30 | 31 | 32 | 33 | 34 | com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder 35 | 36 | 37 | 38 | 39 | 40 | org.eclipse.jem.workbench.JavaEMFNature 41 | org.eclipse.wst.common.modulecore.ModuleCoreNature 42 | org.eclipse.wst.common.project.facet.core.nature 43 | org.eclipse.jdt.core.javanature 44 | org.eclipse.wst.jsdt.core.jsNature 45 | 46 | 47 | -------------------------------------------------------------------------------- /.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.7 8 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BookStore 2 | 带mysql数据库的网上书店系统 3 | ###含邮箱注册激活、在线支付、生成订单、增删改查购物车等功能 4 | -------------------------------------------------------------------------------- /WebRoot/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mysql.jdbc.Driver 5 | jdbc:mysql://localhost:3306/bookstore 6 | zp 7 | a 8 | 10 9 | 30 10 | 100 11 | 10 12 | 200 13 | 14 | -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/Test/TestCon.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/Test/TestCon.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/bean/Cart.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/bean/Cart.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/bean/CartItem.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/bean/CartItem.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/commons/Page.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/commons/Page.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/controller/ClientServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/controller/ClientServlet.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/controller/LoginServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/controller/LoginServlet.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/controller/ManageServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/controller/ManageServlet.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/controller/PayServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/controller/PayServlet.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/controller/ResponsePayServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/controller/ResponsePayServlet.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/BookDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/BookDao.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/CategoryDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/CategoryDao.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/CustomerDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/CustomerDao.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/OrderDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/OrderDao.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/PrivilegeDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/PrivilegeDao.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/impl/BookDaoImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/impl/BookDaoImpl.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/impl/CategoryDaoImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/impl/CategoryDaoImpl.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/impl/CustomerDaoImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/impl/CustomerDaoImpl.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/impl/OrderDaoImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/impl/OrderDaoImpl.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/dao/impl/PrivilegeDaoImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/dao/impl/PrivilegeDaoImpl.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/domain/Book.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/domain/Book.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/domain/Category.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/domain/Category.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/domain/Customer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/domain/Customer.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/domain/Function.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/domain/Function.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/domain/Order.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/domain/Order.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/domain/OrderItem.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/domain/OrderItem.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/domain/Role.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/domain/Role.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/domain/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/domain/User.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/filter/CharseEncodingFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/filter/CharseEncodingFilter.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/filter/GetHttpServletRequest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/filter/GetHttpServletRequest.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/filter/PrivilegeFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/filter/PrivilegeFilter.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/service/BusinessService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/service/BusinessService.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/service/PrivilegeService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/service/PrivilegeService.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/service/impl/BusinessServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/service/impl/BusinessServiceImpl.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/service/impl/PrivilegeServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/service/impl/PrivilegeServiceImpl.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/utils/C3P0Util.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/utils/C3P0Util.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/utils/Constant.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/utils/Constant.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/utils/OrderNumUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/utils/OrderNumUtil.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/utils/PaymentUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/utils/PaymentUtil.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/utils/SendMailThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/utils/SendMailThread.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/classes/cn/tf/utils/WebUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/classes/cn/tf/utils/WebUtil.class -------------------------------------------------------------------------------- /WebRoot/WEB-INF/lib/c3p0-0.9.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/lib/c3p0-0.9.1.2.jar -------------------------------------------------------------------------------- /WebRoot/WEB-INF/lib/commons-beanutils-1.8.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/lib/commons-beanutils-1.8.3.jar -------------------------------------------------------------------------------- /WebRoot/WEB-INF/lib/commons-dbutils-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/lib/commons-dbutils-1.4.jar -------------------------------------------------------------------------------- /WebRoot/WEB-INF/lib/commons-fileupload-1.2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/lib/commons-fileupload-1.2.2.jar -------------------------------------------------------------------------------- /WebRoot/WEB-INF/lib/commons-io-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/lib/commons-io-2.2.jar -------------------------------------------------------------------------------- /WebRoot/WEB-INF/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /WebRoot/WEB-INF/lib/mail.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/lib/mail.jar -------------------------------------------------------------------------------- /WebRoot/WEB-INF/lib/mysql-connector-java-5.0.8-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdksdk0/BookStore/f9506bab7946a96643b53c678e1dd68c360a27cb/WebRoot/WEB-INF/lib/mysql-connector-java-5.0.8-bin.jar -------------------------------------------------------------------------------- /WebRoot/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 16 | 17 | 18 | 19 | ManageServlet 20 | cn.tf.controller.ManageServlet 21 | 22 | 23 | ClientServlet 24 | cn.tf.controller.ClientServlet 25 | 26 | 27 | PayServlet 28 | cn.tf.controller.PayServlet 29 | 30 | 31 | ResponsePayServlet 32 | cn.tf.controller.ResponsePayServlet 33 | 34 | 35 | LoginServlet 36 | cn.tf.controller.LoginServlet 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | ManageServlet 45 | /servlet/ManageServlet 46 | 47 | 48 | ClientServlet 49 | /servlet/ClientServlet 50 | 51 | 52 | PayServlet 53 | /servlet/PayServlet 54 | 55 | 56 | ResponsePayServlet 57 | /servlet/ResponsePayServlet 58 | 59 | 60 | LoginServlet 61 | /servlet/LoginServlet 62 | 63 | 64 | -------------------------------------------------------------------------------- /WebRoot/commons/page.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 |
3 | 第${page.pageNum}页/共${page.totalPageSize}页   4 | 首页   5 | 上一页   6 | 7 | 下一页   8 | 尾页   9 | 15 |    16 | 17 | 38 |
-------------------------------------------------------------------------------- /WebRoot/css/main.css: -------------------------------------------------------------------------------- 1 | .odd{ 2 | background-color: #c3f3c3; 3 | } 4 | .even{ 5 | background-color: #f3c3f3; 6 | } -------------------------------------------------------------------------------- /WebRoot/header.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 3 | 4 | 5 | 6 | Welcome 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |

19 |

欢迎光临

20 |
21 | 首页 22 | 23 | 注册 24 | 登录 25 | 26 | 27 | ${sessionScope.customer.username } 28 | 注销 29 | 30 | 31 | 32 | 我的订单 33 | 我的购物车 34 |
35 | -------------------------------------------------------------------------------- /WebRoot/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | 11 | 12 | My JSP 'index.jsp' starting page 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /WebRoot/js/util.js: -------------------------------------------------------------------------------- 1 | function getXhr() { 2 | var xmlHttp; 3 | try { 4 | // Firefox, Opera 8.0+, Safari 5 | xmlHttp = new XMLHttpRequest(); 6 | } catch (e) { 7 | // Internet Explorer 8 | try { 9 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 10 | } catch (e) { 11 | try { 12 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 13 | } catch (e) { 14 | alert("您的浏览器不支持AJAX!"); 15 | return null; 16 | } 17 | } 18 | } 19 | return xmlHttp; 20 | } 21 | -------------------------------------------------------------------------------- /WebRoot/listBooks.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/header.jsp"%> 3 |
4 | 商品分类: 5 | 6 | ${c.name}   7 | 8 |
9 | 10 | 11 | 12 | 19 | 20 | 21 |
13 |
14 | 书名:${b.name}
15 | 作者:${b.author}
16 | 售价:${b.price}
17 | 放入购物车 18 |
22 | <%@ include file="/commons/page.jsp"%> 23 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /WebRoot/listOrders.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/header.jsp"%> 3 |

您的订单信息如下

4 | 5 | 您还没有购买任何商品 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 34 | 47 | 48 | 49 |
订单号订单金额数量状态操作
${o.ordernum}${o.price}${o.number} 22 | 23 | 24 | 未付款 25 | 26 | 27 | 已付款 28 | 29 | 30 | 有待开发 31 | 32 | 33 | 35 | 36 | 37 | 付款 38 | 39 | 40 | 跟踪 41 | 42 | 43 | 有待开发 44 | 45 | 46 |
50 |
51 | 52 | 53 | -------------------------------------------------------------------------------- /WebRoot/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/header.jsp"%> 3 |

新用户注册

4 |
5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 22 | 23 |
用户名: 9 | 10 |
密码: 15 | 16 |
20 | 21 |
24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /WebRoot/manage/addBook.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/manage/header.jsp"%> 3 |

当前位置:添加书籍

4 |
5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 45 | 46 |
书名: 9 | 10 |
作者: 15 | 16 |
单价: 21 | 元 22 |
图片: 27 | 28 |
描述: 33 | 34 |
所属分类: 39 | 44 |
47 | 48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /WebRoot/manage/addCategory.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/manage/header.jsp"%> 3 |

当前位置:添加新分类

4 |
5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 17 | 18 |
分类名称: 9 | 10 |
描述: 15 | 16 |
19 | 20 |
21 | 22 | 23 | 24 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /WebRoot/manage/header.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 3 | 4 | 5 | 6 | 7 | 8 | 9 | My JSP 'header.jsp' starting page 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |

25 |

后台管理

26 |
27 | 添加分类 28 | 查询分类 29 | 添加书籍 30 | 查询书籍 31 | 待处理订单 32 | 已处理订单 33 |
34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /WebRoot/manage/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/manage/header.jsp"%> 3 |

欢迎

4 | 5 | 6 | -------------------------------------------------------------------------------- /WebRoot/manage/listBooks.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/manage/header.jsp"%> 3 |

当前位置:查询书籍

4 | 5 |

您还没有添加任何书籍,添加

6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 33 | 34 |
图片书名作者售价描述所属分类操作
21 | 22 | ${b.name}${b.author}${b.price}${b.des}${b.category.name} 29 | [修改] 30 | [删除] 31 |
35 | <%@ include file="/commons/page.jsp"%> 36 |
37 | 38 | 39 | -------------------------------------------------------------------------------- /WebRoot/manage/listCategories.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/manage/header.jsp"%> 3 | 4 |
5 |

当前位置:查询分类

6 | 7 |

您还没有添加任何分类,添加

8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 30 | 31 | 32 |
选择序号分类名称描述操作
21 | 22 | ${vs.count}${c.name}${c.des} 27 | [修改] 28 | [删除] 29 |
33 |
34 |
35 | 36 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /WebRoot/manage/message.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/manage/header.jsp"%> 3 |

${message}

4 | 5 |
6 | 7 | 8 | -------------------------------------------------------------------------------- /WebRoot/message.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/header.jsp"%> 3 |

${message}

4 | 5 | 6 | -------------------------------------------------------------------------------- /WebRoot/passport/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | 3 | 4 | 5 | 6 | 用户登陆 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 用户名:
18 | 密码:
19 | 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /WebRoot/pay.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | 11 | 12 | 在线支付 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 |
26 | 27 | 28 | 31 | 32 | 33 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 58 | 60 | 61 | 62 | 63 | 65 | 66 | 67 | 69 | 70 |
29 | 订单号: 30 | 支付金额:

34 |
请您选择在线支付银行
招商银行 41 | 工商银行农业银行建设银行 45 |
中国民生银行总行光大银行 50 | 交通银行深圳发展银行
北京银行兴业银行 57 | 上海浦东发展银行 59 | 中信银行

64 |
68 |
71 |
72 | 73 |
74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /WebRoot/regist.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/header.jsp"%> 3 |

新用户注册

4 |
5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 38 | 39 |
用户名: 9 | 10 |
密码: 15 | 16 |
电话: 21 | 22 |
地址:
邮箱: 31 | 32 |
36 | 37 |
40 |
41 | 42 | 43 | -------------------------------------------------------------------------------- /WebRoot/showCart.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%@ include file="/header.jsp"%> 3 |

您购物车中的商品信息

4 | 5 | 您还没有购买任何商品 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | 35 | 36 |
书名作者单价数量小计操作
${me.value.book.name}${me.value.book.author}${me.value.book.price}${me.value.price} 25 | 删除 26 |
31 | 总数量:${sessionScope.cart.number}   32 | 总金额:${sessionScope.cart.price}   33 | 去结算 34 |
37 |
38 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /WebRoot/sure.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | 3 | 4 | 5 | 6 | title 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /db.sql: -------------------------------------------------------------------------------- 1 | 2 | create database bookstore; 3 | 4 | use bookstore; 5 | 6 | --分类表 7 | create table categorys( 8 | id VARCHAR(100) PRIMARY KEY, 9 | name varchar(100) not null unique, 10 | des varchar(255) 11 | ); 12 | 13 | --图书表 14 | create table books( 15 | id varchar(100) primary key, 16 | name varchar(100), 17 | author varchar(100), 18 | price float(8,2), 19 | path varchar(100), 20 | filename varchar(100), 21 | des varchar(255), 22 | categoryId varchar(100), 23 | CONSTRAINT category_id_fk FOREIGN KEY (categoryId) REFERENCES categorys(id) 24 | 25 | ) 26 | 27 | 28 | 29 | 30 | 31 | --用户表 32 | create table customers( 33 | id varchar(100) primary key, 34 | username varchar(100) not null unique, 35 | password varchar(100) not null, 36 | phone varchar(20) not null unique, 37 | address varchar(255) not null , 38 | email varchar(20) not null unique, 39 | code varchar(200) unique, 40 | actived bit(1) 41 | ) 42 | 43 | --订单表 44 | create table orders( 45 | ordernum varchar(100) primary key, 46 | price float(8,2), 47 | number int, 48 | status int, 49 | customerId VARCHAR(100), 50 | CONSTRAINT customerId_fk FOREIGN KEY (customerId) REFERENCES customers(id) 51 | ) 52 | ) 53 | 54 | --订单详情表 55 | create table orderitems( 56 | id varchar(100) primary key, 57 | number int, 58 | price float(8,2), 59 | ordernum varchar(100), 60 | bookid varchar(100), 61 | CONSTRAINT ordernum_fk FOREIGN KEY (ordernum) REFERENCES orders(ordernum), 62 | CONSTRAINT bookid_fk FOREIGN KEY (bookid) REFERENCES books(id) 63 | ) 64 | 65 | --订单编号表 66 | create table ordernum( 67 | prefix date, 68 | num int 69 | ) 70 | 71 | 72 | --权限控制 73 | create table users( 74 | id varchar(100) primary key, 75 | username varchar(100) not null unique, 76 | password varchar(100) not null 77 | ); 78 | 79 | create table roles( 80 | id varchar(100) primary key, 81 | name varchar(100) not null unique, 82 | des varchar(255) 83 | ); 84 | 85 | create table functions( 86 | id varchar(100) primary key, 87 | name varchar(100) not null unique, 88 | uri varchar(255) 89 | ) 90 | 91 | CREATE TABLE role_function( 92 | r_id VARCHAR(100), 93 | f_id VARCHAR(100), 94 | PRIMARY KEY(r_id,f_id), 95 | CONSTRAINT role_id_fk1 FOREIGN KEY (r_id) REFERENCES roles(id), 96 | CONSTRAINT function_id_fk FOREIGN KEY (f_id) REFERENCES functions(id) 97 | ); 98 | CREATE TABLE user_role( 99 | u_id VARCHAR(100), 100 | r_id VARCHAR(100), 101 | PRIMARY KEY(u_id,r_id), 102 | CONSTRAINT user_id_fk FOREIGN KEY (u_id) REFERENCES users(id), 103 | CONSTRAINT role_id_fk2 FOREIGN KEY (r_id) REFERENCES roles(id) 104 | ); 105 | 106 | insert into `functions` (`id`, `name`, `uri`) values('1','主页','/BookStore/manage/index.jsp'); 107 | insert into `functions` (`id`, `name`, `uri`) values('2','消息','/BookStore/manage/message.jsp'); 108 | insert into `functions` (`id`, `name`, `uri`) values('3','添加分类','/BookStore/manage/addCategory.jsp'); 109 | insert into `functions` (`id`, `name`, `uri`) values('4','查询分类','/BookStore/servlet/ManageServlet?op=listCategories'); 110 | insert into `functions` (`id`, `name`, `uri`) values('5','添加书籍','/BookStore/servlet/ManageServlet?op=addBookUI'); 111 | insert into `functions` (`id`, `name`, `uri`) values('6','查询书籍','/BookStore/servlet/ManageServlet?op=listBooks'); 112 | 113 | 114 | insert into `role_function` (`r_id`, `f_id`) values('1','1'); 115 | insert into `role_function` (`r_id`, `f_id`) values('2','1'); 116 | insert into `role_function` (`r_id`, `f_id`) values('1','2'); 117 | insert into `role_function` (`r_id`, `f_id`) values('2','2'); 118 | insert into `role_function` (`r_id`, `f_id`) values('1','3'); 119 | insert into `role_function` (`r_id`, `f_id`) values('1','4'); 120 | insert into `role_function` (`r_id`, `f_id`) values('1','5'); 121 | insert into `role_function` (`r_id`, `f_id`) values('2','5'); 122 | insert into `role_function` (`r_id`, `f_id`) values('1','6'); 123 | insert into `role_function` (`r_id`, `f_id`) values('2','6'); 124 | 125 | 126 | insert into `roles` (`id`, `name`, `des`) values('1','超级管理员','可以访问任何页面'); 127 | insert into `roles` (`id`, `name`, `des`) values('2','普通管理员','书籍部分'); 128 | 129 | 130 | insert into `users` (`id`, `username`, `password`) values('1','admin','123'); 131 | insert into `users` (`id`, `username`, `password`) values('2','aa','123'); 132 | 133 | 134 | insert into `user_role` (`u_id`, `r_id`) values('1','1'); 135 | insert into `user_role` (`u_id`, `r_id`) values('2','2'); 136 | 137 | -------------------------------------------------------------------------------- /src/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mysql.jdbc.Driver 5 | jdbc:mysql://localhost:3306/bookstore 6 | zp 7 | a 8 | 10 9 | 30 10 | 100 11 | 10 12 | 200 13 | 14 | -------------------------------------------------------------------------------- /src/cn/tf/Test/TestCon.java: -------------------------------------------------------------------------------- 1 | package cn.tf.Test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.List; 6 | 7 | import javax.validation.constraints.AssertTrue; 8 | 9 | import org.junit.Test; 10 | 11 | import cn.tf.domain.Category; 12 | import cn.tf.service.BusinessService; 13 | import cn.tf.service.impl.BusinessServiceImpl; 14 | 15 | public class TestCon { 16 | 17 | private BusinessService s=new BusinessServiceImpl(); 18 | 19 | @Test 20 | public void testAdd() { 21 | 22 | Category c=new Category(); 23 | c.setName("数据结构"); 24 | c.setDes("数据结构是非常重要的"); 25 | s.addCategory(c); 26 | 27 | } 28 | 29 | @Test 30 | public void testFildAll(){ 31 | List cs=s.findAllCategories(); 32 | for(Category c:cs){ 33 | System.out.println(c); 34 | } 35 | } 36 | 37 | 38 | @Test 39 | public void testCategoryExists(){ 40 | boolean b=s.isCategoryExists("数据结构"); 41 | assertTrue(b); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/cn/tf/bean/Cart.java: -------------------------------------------------------------------------------- 1 | package cn.tf.bean; 2 | 3 | import java.io.Serializable; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import cn.tf.domain.Book; 8 | 9 | public class Cart implements Serializable{ 10 | 11 | private Map items = new HashMap(); 12 | private float price;//总价 13 | private int number;//总数量 14 | public Map getItems() { 15 | return items; 16 | } 17 | //向items中添加一项 18 | public void addBook2Items(Book book){ 19 | //书在items中有:数量加1 20 | if(items.containsKey(book.getId())){ 21 | CartItem item = items.get(book.getId()); 22 | item.setNumber(item.getNumber()+1); 23 | }else{ 24 | //没有:创建一个新项 25 | CartItem item = new CartItem(book); 26 | item.setNumber(1); 27 | items.put(book.getId(), item); 28 | } 29 | } 30 | 31 | public float getPrice() { 32 | price = 0; 33 | for(Map.Entry me:items.entrySet()){ 34 | price+=me.getValue().getPrice(); 35 | } 36 | return price; 37 | } 38 | public void setPrice(float price) { 39 | this.price = price; 40 | } 41 | public int getNumber() { 42 | number = 0; 43 | for(Map.Entry me:items.entrySet()){ 44 | number+=me.getValue().getNumber(); 45 | } 46 | return number; 47 | } 48 | public void setNumber(int number) { 49 | this.number = number; 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/cn/tf/bean/CartItem.java: -------------------------------------------------------------------------------- 1 | package cn.tf.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | import cn.tf.domain.Book; 6 | 7 | //购物项 8 | public class CartItem implements Serializable{ 9 | 10 | private Book book;//该项对应的书籍 11 | private float price;//小计:单价*数量 12 | private int number;//数量 13 | 14 | public CartItem(Book book){ 15 | this.book = book; 16 | } 17 | 18 | public Book getBook() { 19 | return book; 20 | } 21 | public void setBook(Book book) { 22 | this.book = book; 23 | } 24 | 25 | public void setPrice(float price) { 26 | this.price = price; 27 | } 28 | 29 | public float getPrice() { 30 | return book.getPrice()*number; 31 | } 32 | public int getNumber() { 33 | return number; 34 | } 35 | public void setNumber(int number) { 36 | this.number = number; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/cn/tf/commons/Page.java: -------------------------------------------------------------------------------- 1 | package cn.tf.commons; 2 | 3 | import java.util.List; 4 | 5 | public class Page { 6 | 7 | private List records; 8 | private int pageSize = 3;//每页显示的记录条数 9 | private int pageNum;//当前页码 10 | 11 | private int totalPageSize;//总页数 12 | private int startIndex;//每页开始的记录索引 13 | private int totalRecordsNum;//总记录条数 14 | 15 | private int prePageNum;//上一页 16 | private int nextPageNum;//下一页 17 | 18 | private String url;//查询分页的地址 19 | 20 | public Page(int pageNum,int totalRecordsNum){ 21 | this.pageNum = pageNum; 22 | this.totalRecordsNum = totalRecordsNum; 23 | //计算总页数 24 | totalPageSize = totalRecordsNum%pageSize==0?totalRecordsNum/pageSize:totalRecordsNum/pageSize+1; 25 | //开始记录的索引 26 | startIndex = (pageNum-1)*pageSize; 27 | prePageNum = pageNum-1<1?1:pageNum-1; 28 | nextPageNum = pageNum+1>totalPageSize?totalPageSize:pageNum+1; 29 | } 30 | 31 | 32 | public List getRecords() { 33 | return records; 34 | } 35 | 36 | public void setRecords(List records) { 37 | this.records = records; 38 | } 39 | 40 | public int getPageSize() { 41 | return pageSize; 42 | } 43 | 44 | public void setPageSize(int pageSize) { 45 | this.pageSize = pageSize; 46 | } 47 | 48 | public int getPageNum() { 49 | return pageNum; 50 | } 51 | 52 | public void setPageNum(int pageNum) { 53 | this.pageNum = pageNum; 54 | } 55 | 56 | public int getTotalPageSize() { 57 | return totalPageSize; 58 | } 59 | 60 | public void setTotalPageSize(int totalPageSize) { 61 | this.totalPageSize = totalPageSize; 62 | } 63 | 64 | public int getStartIndex() { 65 | return startIndex; 66 | } 67 | 68 | public void setStartIndex(int startIndex) { 69 | this.startIndex = startIndex; 70 | } 71 | 72 | public int getTotalRecordsNum() { 73 | return totalRecordsNum; 74 | } 75 | 76 | public void setTotalRecordsNum(int totalRecordsNum) { 77 | this.totalRecordsNum = totalRecordsNum; 78 | } 79 | 80 | public int getPrePageNum() { 81 | return prePageNum; 82 | } 83 | 84 | public void setPrePageNum(int prePageNum) { 85 | this.prePageNum = prePageNum; 86 | } 87 | 88 | public int getNextPageNum() { 89 | return nextPageNum; 90 | } 91 | 92 | public void setNextPageNum(int nextPageNum) { 93 | this.nextPageNum = nextPageNum; 94 | } 95 | 96 | public String getUrl() { 97 | return url; 98 | } 99 | 100 | public void setUrl(String url) { 101 | this.url = url; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/cn/tf/controller/ClientServlet.java: -------------------------------------------------------------------------------- 1 | package cn.tf.controller; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.UUID; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.servlet.http.HttpSession; 14 | 15 | import cn.tf.bean.Cart; 16 | import cn.tf.bean.CartItem; 17 | import cn.tf.commons.Page; 18 | import cn.tf.domain.Book; 19 | import cn.tf.domain.Category; 20 | import cn.tf.domain.Customer; 21 | import cn.tf.domain.Order; 22 | import cn.tf.domain.OrderItem; 23 | import cn.tf.service.BusinessService; 24 | import cn.tf.service.impl.BusinessServiceImpl; 25 | import cn.tf.utils.OrderNumUtil; 26 | import cn.tf.utils.SendMailThread; 27 | import cn.tf.utils.WebUtil; 28 | 29 | public class ClientServlet extends HttpServlet { 30 | 31 | private BusinessService s=new BusinessServiceImpl(); 32 | 33 | public void doGet(HttpServletRequest request, HttpServletResponse response) 34 | throws ServletException, IOException { 35 | 36 | String op=request.getParameter("op"); 37 | if("listBooks".equals(op)){ 38 | listBooks(request,response); 39 | }else if("listBookByCategory".equals(op)){ 40 | listBookByCategory(request,response); 41 | }else if("buyBook".equals(op)){ 42 | buyBook(request,response); 43 | }else if("delOneItem".equals(op)){ 44 | delOneItem(request,response); 45 | }else if("changeNum".equals(op)){ 46 | changeNum(request,response); 47 | }else if("customerRegist".equals(op)){ 48 | customerRegist(request,response); 49 | }else if("activeCustomer".equals(op)){ 50 | activeCustomer(request,response); 51 | }else if("login".equals(op)){ 52 | login(request,response); 53 | }else if("logout".equals(op)){ 54 | logout(request,response); 55 | }else if("genOrder".equals(op)){ 56 | genOrder(request,response); 57 | }else if("showOrders".equals(op)){ 58 | showOrders(request,response); 59 | } 60 | 61 | } 62 | 63 | 64 | //订单详情 65 | private void showOrders(HttpServletRequest request, 66 | HttpServletResponse response) throws IOException, ServletException { 67 | //检测是否登录; 68 | HttpSession session=request.getSession(); 69 | Customer customer=(Customer) session.getAttribute("customer"); 70 | if(customer==null){ 71 | response.getWriter().write("请先登录"); 72 | response.setHeader("Refresh", "2;URL="+request.getContextPath()); 73 | return ; 74 | } 75 | List orders=s.findOrdersByCustomerId(customer.getId()); 76 | request.setAttribute("orders", orders); 77 | 78 | request.getRequestDispatcher("/listOrders.jsp").forward(request, response); 79 | 80 | 81 | 82 | } 83 | 84 | 85 | //生成订单 86 | private void genOrder(HttpServletRequest request, 87 | HttpServletResponse response) throws IOException, ServletException { 88 | //检测是否登录; 89 | HttpSession session=request.getSession(); 90 | Customer customer=(Customer) session.getAttribute("customer"); 91 | if(customer==null){ 92 | response.getWriter().write("请先登录"); 93 | response.setHeader("Refresh", "2;URL="+request.getContextPath()); 94 | return ; 95 | } 96 | 97 | Cart cart=(Cart) request.getSession().getAttribute("cart"); 98 | 99 | Order order=new Order(); 100 | order.setOrdernum(OrderNumUtil.genOrderNum()); 101 | order.setPrice(cart.getPrice()); 102 | order.setNumber(cart.getNumber()); 103 | order.setCustomer(customer); 104 | 105 | 106 | List oItems=new ArrayList(); 107 | //设置订单项 108 | for(Map.Entry me:cart.getItems().entrySet()){ 109 | OrderItem item=new OrderItem(); 110 | item.setId(UUID.randomUUID().toString()); 111 | item.setNumber(me.getValue().getNumber()); 112 | item.setPrice(me.getValue().getPrice()); 113 | item.setBook(me.getValue().getBook()); 114 | oItems.add(item); 115 | } 116 | //建立和订单的关系 117 | order.setItems(oItems); 118 | s.genOrder(order); 119 | request.setAttribute("order", order); 120 | request.getRequestDispatcher("/pay.jsp").forward(request, response); 121 | 122 | 123 | } 124 | 125 | 126 | //注销登录 127 | private void logout(HttpServletRequest request, HttpServletResponse response) throws IOException { 128 | request.getSession().removeAttribute("customer"); 129 | response.getWriter().write("注销成功!2秒后转向主页"); 130 | response.setHeader("Refresh", "2;URL="+request.getContextPath()); 131 | 132 | } 133 | 134 | 135 | //用户登录 136 | private void login(HttpServletRequest request, HttpServletResponse response) throws IOException { 137 | String username=request.getParameter("username"); 138 | String password=request.getParameter("password"); 139 | Customer customer=s.login(username, password); 140 | if(customer==null){ 141 | response.getWriter().write("错误的用户名或密码,或者您的账户还没有激活!5秒后转向登陆页"); 142 | response.setHeader("Refresh", "5;URL="+request.getContextPath()+"/login.jsp"); 143 | return; 144 | } 145 | request.getSession().setAttribute("customer", customer); 146 | response.getWriter().write("登陆成功!2秒后转向主页"); 147 | response.setHeader("Refresh", "2;URL="+request.getContextPath()); 148 | 149 | } 150 | 151 | 152 | //激活邮箱 153 | private void activeCustomer(HttpServletRequest request, 154 | HttpServletResponse response) throws IOException { 155 | 156 | String code=request.getParameter("code"); 157 | 158 | Customer customer=s.findByCode(code); 159 | if(customer==null){ 160 | response.getWriter().write("发生未知错误,请重新输入"); 161 | return ; 162 | } 163 | customer.setActived(true); 164 | s.activeCustomer(customer); 165 | response.getWriter().write("激活成功!2秒后转向主页"); 166 | response.setHeader("Refresh", "2;URL="+request.getContextPath()); 167 | 168 | } 169 | 170 | 171 | //新用户注册,发送激活邮件 172 | private void customerRegist(HttpServletRequest request, 173 | HttpServletResponse response) throws ServletException, IOException { 174 | 175 | //封装数据 176 | Customer customer=WebUtil.fillBean(request,Customer.class); 177 | customer.setCode(UUID.randomUUID().toString()); 178 | //发送邮件,单独启动一个线程 179 | SendMailThread smt=new SendMailThread(customer); 180 | smt.start(); 181 | s.registCustomer(customer); 182 | 183 | request.setAttribute("message", "注册成功,我们已经发送了一封激活邮件到您的"+customer.getEmail()+"中,请及时激活您的账户"); 184 | request.getRequestDispatcher("/message.jsp").forward(request, response); 185 | 186 | } 187 | 188 | 189 | //改变数量 190 | private void changeNum(HttpServletRequest request, 191 | HttpServletResponse response) throws IOException { 192 | 193 | String bookId=request.getParameter("bookId"); 194 | Cart cart=(Cart) request.getSession().getAttribute("cart"); 195 | CartItem item=cart.getItems().get(bookId); 196 | item.setNumber(Integer.parseInt(request.getParameter("num"))); 197 | 198 | response.sendRedirect(request.getContextPath()+"/showCart.jsp"); 199 | } 200 | 201 | 202 | 203 | 204 | //删除购物车中的一项 205 | private void delOneItem(HttpServletRequest request, 206 | HttpServletResponse response) throws IOException { 207 | 208 | String bookId=request.getParameter("bookId"); 209 | Book book=s.findBookById(bookId); 210 | 211 | Cart cart=(Cart) request.getSession().getAttribute("cart"); 212 | cart.getItems().remove(bookId); 213 | 214 | response.sendRedirect(request.getContextPath()+"/showCart.jsp"); 215 | 216 | } 217 | 218 | //加入购物车 219 | private void buyBook(HttpServletRequest request, 220 | HttpServletResponse response) { 221 | //得到书籍 222 | String bookId=request.getParameter("bookId"); 223 | Book book=s.findBookById(bookId); 224 | 225 | //购物车 226 | HttpSession session=request.getSession(); 227 | Cart cart=(Cart) session.getAttribute("cart"); 228 | if(cart==null){ 229 | cart=new Cart(); 230 | session.setAttribute("cart", cart); 231 | } 232 | cart.addBook2Items(book); 233 | //提示 234 | request.setAttribute("message", "购买成功!返回"); 235 | try { 236 | request.getRequestDispatcher("/message.jsp").forward(request,response); 237 | } catch (ServletException e) { 238 | // TODO Auto-generated catch block 239 | e.printStackTrace(); 240 | } catch (IOException e) { 241 | // TODO Auto-generated catch block 242 | e.printStackTrace(); 243 | } 244 | 245 | 246 | } 247 | 248 | //按照分类查询书籍的分页信息 249 | private void listBookByCategory(HttpServletRequest request, 250 | HttpServletResponse response) { 251 | List cs=s.findAllCategories(); 252 | request.setAttribute("cs", cs); 253 | 254 | //查询所有商品的分页数据 255 | String num=request.getParameter("num"); 256 | String categoryId=request.getParameter("categoryId"); 257 | Page page=s.findPage(num,categoryId); 258 | 259 | page.setUrl("/servlet/ClientServlet?op=listBookByCategory&categoryId="+categoryId); 260 | request.setAttribute("page", page); 261 | try { 262 | request.getRequestDispatcher("/listBooks.jsp").forward(request, response); 263 | } catch (ServletException e) { 264 | // TODO Auto-generated catch block 265 | e.printStackTrace(); 266 | } catch (IOException e) { 267 | // TODO Auto-generated catch block 268 | e.printStackTrace(); 269 | } 270 | 271 | 272 | } 273 | 274 | private void listBooks(HttpServletRequest request, 275 | HttpServletResponse response) throws ServletException, IOException { 276 | //查询所有分类 277 | List cs=s.findAllCategories(); 278 | request.setAttribute("cs", cs); 279 | 280 | //查询所有商品的分页数据 281 | String num=request.getParameter("num"); 282 | Page page=s.findPage(num); 283 | page.setUrl("/servlet/ClientServlet?op=listBooks"); 284 | request.setAttribute("page", page); 285 | request.getRequestDispatcher("/listBooks.jsp").forward(request, response); 286 | 287 | 288 | 289 | } 290 | 291 | public void doPost(HttpServletRequest request, HttpServletResponse response) 292 | throws ServletException, IOException { 293 | 294 | doGet(request,response); 295 | } 296 | 297 | } 298 | -------------------------------------------------------------------------------- /src/cn/tf/controller/LoginServlet.java: -------------------------------------------------------------------------------- 1 | package cn.tf.controller; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import cn.tf.domain.User; 12 | import cn.tf.service.PrivilegeService; 13 | import cn.tf.service.impl.PrivilegeServiceImpl; 14 | 15 | public class LoginServlet extends HttpServlet { 16 | 17 | private PrivilegeService s=new PrivilegeServiceImpl(); 18 | 19 | public void doGet(HttpServletRequest request, HttpServletResponse response) 20 | throws ServletException, IOException { 21 | 22 | String username=request.getParameter("username"); 23 | String password=request.getParameter("password"); 24 | User user=s.login(username,password); 25 | if(user==null){ 26 | response.getWriter().write("用户名或密码错误"); 27 | response.setHeader("Refresh","2;URL="+request.getContextPath()+"/passport/login.jsp"); 28 | return; 29 | 30 | } 31 | 32 | request.getSession().setAttribute("user",user); 33 | response.getWriter().write("登录成功"); 34 | response.setHeader("Refresh","1;URL="+request.getContextPath()+"/manage/index.jsp"); 35 | 36 | 37 | 38 | } 39 | 40 | public void doPost(HttpServletRequest request, HttpServletResponse response) 41 | throws ServletException, IOException { 42 | 43 | doGet(request,response); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/cn/tf/controller/ManageServlet.java: -------------------------------------------------------------------------------- 1 | package cn.tf.controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.io.UnsupportedEncodingException; 7 | import java.text.DateFormat; 8 | import java.text.SimpleDateFormat; 9 | import java.util.ArrayList; 10 | import java.util.Date; 11 | import java.util.List; 12 | import java.util.UUID; 13 | 14 | import javax.servlet.ServletException; 15 | import javax.servlet.http.HttpServlet; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | 19 | import org.apache.commons.beanutils.BeanUtils; 20 | import org.apache.commons.fileupload.FileItem; 21 | import org.apache.commons.fileupload.FileUploadException; 22 | import org.apache.commons.fileupload.disk.DiskFileItemFactory; 23 | import org.apache.commons.fileupload.servlet.ServletFileUpload; 24 | import org.apache.commons.io.FilenameUtils; 25 | 26 | import cn.tf.commons.Page; 27 | import cn.tf.domain.Book; 28 | import cn.tf.domain.Category; 29 | import cn.tf.service.BusinessService; 30 | import cn.tf.service.impl.BusinessServiceImpl; 31 | import cn.tf.utils.WebUtil; 32 | 33 | public class ManageServlet extends HttpServlet { 34 | 35 | private BusinessService s=new BusinessServiceImpl(); 36 | 37 | public void doGet(HttpServletRequest request, HttpServletResponse response) 38 | throws ServletException, IOException { 39 | 40 | String op=request.getParameter("op"); 41 | if("checkCategory".equals(op)){ 42 | checkCategory(request,response); 43 | }else if("addCategory".equals(op)){ 44 | addCategory(request,response); 45 | }else if("listCategories".equals(op)){ 46 | listCategories(request,response); 47 | }else if("addBookUI".equals(op)){ 48 | addBookUI(request,response); 49 | }else if("delCategory".equals(op)){ 50 | delCategory(request,response); 51 | }else if("addBook".equals(op)){ 52 | addBook(request,response); 53 | }else if("listBooks".equals(op)){ 54 | listBooks(request,response); 55 | } 56 | 57 | } 58 | 59 | //分页显示书籍 60 | private void listBooks(HttpServletRequest request, 61 | HttpServletResponse response) throws ServletException, IOException { 62 | 63 | String num=request.getParameter("num"); 64 | Page page=s.findPage(num); 65 | page.setUrl("/servlet/ManageServlet?op=listBooks"); 66 | request.setAttribute("page", page); 67 | request.getRequestDispatcher("/manage/listBooks.jsp").forward(request, response); 68 | 69 | 70 | 71 | } 72 | 73 | //保存书籍 74 | private void addBook(HttpServletRequest request, 75 | HttpServletResponse response) throws UnsupportedEncodingException { 76 | 77 | boolean isMultipart=ServletFileUpload.isMultipartContent(request); 78 | if(!isMultipart){ 79 | throw new RuntimeException(); 80 | } 81 | 82 | DiskFileItemFactory factory=new DiskFileItemFactory(); 83 | ServletFileUpload sfu=new ServletFileUpload(factory); 84 | List items=new ArrayList(); 85 | 86 | try { 87 | items=sfu.parseRequest(request); 88 | } catch (FileUploadException e) { 89 | throw new RuntimeException(e); 90 | } 91 | Book book=new Book(); 92 | for (FileItem item : items) { 93 | if(item.isFormField()){ 94 | String fieldName=item.getFieldName(); 95 | String fieldValue=item.getString("UTF-8"); 96 | 97 | try { 98 | BeanUtils.setProperty(book, fieldName, fieldValue); 99 | } catch (Exception e) { 100 | e.printStackTrace(); 101 | } 102 | //单独处理categoryId 103 | if("categoryId".equals(fieldName)){ 104 | Category category = s.findCategoryById(fieldValue); 105 | book.setCategory(category); 106 | } 107 | 108 | }else{ 109 | String filename = item.getName(); 110 | 111 | String extensionName = FilenameUtils.getExtension(filename); 112 | 113 | filename = UUID.randomUUID()+"."+extensionName; 114 | book.setFilename(filename); 115 | 116 | 117 | String rootDirectory = getServletContext().getRealPath("../images"); 118 | String childPath = getStoreDirecotry(rootDirectory); 119 | book.setPath(childPath); 120 | 121 | //文件上传 122 | try { 123 | item.write(new File(rootDirectory+File.separator+childPath+File.separator+filename)); 124 | } catch (Exception e) { 125 | e.printStackTrace(); 126 | } 127 | } 128 | } 129 | 130 | s.addBook(book); 131 | request.setAttribute("message", "添加书籍成功"); 132 | try { 133 | request.getRequestDispatcher("/manage/message.jsp").forward(request, response); 134 | } catch (Exception e) { 135 | e.printStackTrace(); 136 | } 137 | 138 | } 139 | 140 | 141 | private String getStoreDirecotry(String rootDirectory) { 142 | Date now = new Date(); 143 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 144 | String path = df.format(now); 145 | File file = new File(rootDirectory,path); 146 | if(!file.exists()){ 147 | file.mkdirs(); 148 | } 149 | return path; 150 | } 151 | 152 | 153 | //删除书籍 154 | private void delCategory(HttpServletRequest request, 155 | HttpServletResponse response) throws ServletException, IOException { 156 | String name=request.getParameter("name"); 157 | 158 | s.delCategory(name); 159 | 160 | request.setAttribute("message", "删除成功"); 161 | request.getRequestDispatcher("/manage/message.jsp?d="+new Date().getTime()).forward(request, response); 162 | 163 | } 164 | 165 | 166 | //添加书籍 167 | private void addBookUI(HttpServletRequest request, 168 | HttpServletResponse response) throws ServletException, IOException { 169 | 170 | 171 | List cs=s.findAllCategories(); 172 | request.setAttribute("cs", cs); 173 | request.getRequestDispatcher("/manage/addBook.jsp").forward(request, response); 174 | 175 | 176 | } 177 | 178 | //查询所有分类信息 179 | private void listCategories(HttpServletRequest request, 180 | HttpServletResponse response) throws ServletException, IOException { 181 | 182 | List cs=s.findAllCategories(); 183 | request.setAttribute("cs", cs); 184 | request.getRequestDispatcher("/manage/listCategories.jsp").forward(request, response); 185 | 186 | 187 | } 188 | 189 | //保存分类数据 190 | private void addCategory(HttpServletRequest request, 191 | HttpServletResponse response) throws ServletException, IOException { 192 | 193 | 194 | Category category=WebUtil.fillBean(request, Category.class); 195 | s.addCategory(category); 196 | 197 | request.setAttribute("message", "添加成功"); 198 | request.getRequestDispatcher("/manage/message.jsp").forward(request, response); 199 | 200 | 201 | 202 | } 203 | 204 | 205 | //检测分类名称是否可用 206 | private void checkCategory(HttpServletRequest request, 207 | HttpServletResponse response) throws IOException { 208 | PrintWriter out=response.getWriter(); 209 | 210 | String name=request.getParameter("name"); 211 | boolean exists=s.isCategoryExists(name); 212 | if(exists){ 213 | out.write("该分类已经存在"); 214 | }else{ 215 | out.write("可以使用"); 216 | } 217 | 218 | 219 | } 220 | 221 | public void doPost(HttpServletRequest request, HttpServletResponse response) 222 | throws ServletException, IOException { 223 | 224 | doGet(request,response); 225 | } 226 | 227 | } 228 | -------------------------------------------------------------------------------- /src/cn/tf/controller/PayServlet.java: -------------------------------------------------------------------------------- 1 | package cn.tf.controller; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import cn.tf.utils.PaymentUtil; 12 | 13 | 14 | 15 | public class PayServlet extends HttpServlet { 16 | 17 | 18 | public void doGet(HttpServletRequest request, HttpServletResponse response) 19 | throws ServletException, IOException { 20 | 21 | request.setCharacterEncoding("UTF-8"); 22 | String ordernum=request.getParameter("ordernum"); 23 | String money=request.getParameter("money"); 24 | String pd_FrpId=request.getParameter("pd_FrpId"); 25 | 26 | 27 | 28 | String p0_Cmd = "Buy"; 29 | String p1_MerId = "10001126856"; 30 | String p2_Order = ordernum; 31 | String p3_Amt = money; 32 | String p4_Cur = "CNY"; 33 | String p5_Pid = "books"; //商品名称 34 | String p6_Pcat = "unknown"; 35 | String p7_Pdesc = "descrition"; 36 | String p8_Url = "http://localhost:8080"+request.getContextPath()+"/servlet/ResponsePayServlet"; 37 | String p9_SAF = "1"; 38 | String pa_MP = "unknown"; 39 | String pr_NeedResponse="1"; 40 | String hmac = PaymentUtil.buildHmac(p0_Cmd, p1_MerId, p2_Order, p3_Amt, p4_Cur, p5_Pid, p6_Pcat, p7_Pdesc, p8_Url, p9_SAF, pa_MP, pd_FrpId, pr_NeedResponse, "69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl"); 41 | 42 | request.setAttribute("p0_Cmd",p0_Cmd ); 43 | request.setAttribute("p1_MerId",p1_MerId ); 44 | request.setAttribute("p2_Order", p2_Order); 45 | request.setAttribute("p3_Amt", p3_Amt); 46 | request.setAttribute("p4_Cur",p4_Cur ); 47 | request.setAttribute("p5_Pid",p5_Pid ); 48 | request.setAttribute("p6_Pcat",p6_Pcat ); 49 | request.setAttribute("p7_Pdesc",p7_Pdesc ); 50 | request.setAttribute("p8_Url",p8_Url ); 51 | request.setAttribute("pa_MP",pa_MP ); 52 | request.setAttribute("pr_NeedResponse",pr_NeedResponse ); 53 | request.setAttribute("hmac",hmac ); 54 | request.setAttribute("p9_SAF",p9_SAF ); 55 | request.setAttribute("pd_FrpId", pd_FrpId); 56 | 57 | request.getRequestDispatcher("/sure.jsp").forward(request, response); 58 | 59 | } 60 | 61 | 62 | public void doPost(HttpServletRequest request, HttpServletResponse response) 63 | throws ServletException, IOException { 64 | 65 | doGet(request,response); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/cn/tf/controller/ResponsePayServlet.java: -------------------------------------------------------------------------------- 1 | package cn.tf.controller; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import cn.tf.domain.Order; 12 | import cn.tf.service.BusinessService; 13 | import cn.tf.service.impl.BusinessServiceImpl; 14 | import cn.tf.utils.PaymentUtil; 15 | 16 | 17 | 18 | public class ResponsePayServlet extends HttpServlet { 19 | 20 | 21 | private BusinessService s=new BusinessServiceImpl(); 22 | 23 | public void doGet(HttpServletRequest request, HttpServletResponse response) 24 | throws ServletException, IOException { 25 | response.setContentType("text/html;charset=UTF-8"); 26 | PrintWriter out = response.getWriter(); 27 | String p1_MerId = request.getParameter("p1_MerId"); 28 | String r0_Cmd = request.getParameter("r0_Cmd"); 29 | String r1_Code = request.getParameter("r1_Code");//支付结果。1代表成功 30 | String r2_TrxId = request.getParameter("r2_TrxId"); 31 | String r3_Amt = request.getParameter("r3_Amt"); 32 | String r4_Cur= request.getParameter("r4_Cur"); 33 | String r5_Pid= request.getParameter("r5_Pid"); 34 | String r6_Order = request.getParameter("r6_Order");//订单编号 35 | String r7_Uid = request.getParameter("r7_Uid"); 36 | String r8_MP = request.getParameter("r8_MP"); 37 | String r9_BType = request.getParameter("r9_BType");//1浏览器访问的。2点对点 38 | String hmac = request.getParameter("hmac"); 39 | 40 | //数据校验 41 | boolean ok = PaymentUtil.verifyCallback(hmac, p1_MerId, r0_Cmd, r1_Code, r2_TrxId, r3_Amt, r4_Cur, r5_Pid, r6_Order, r7_Uid, r8_MP, r9_BType, "69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl"); 42 | if(!ok){ 43 | out.write("数据有可能被篡改,请联系网站"); 44 | }else{ 45 | if("1".equals(r1_Code)){ 46 | //支付成功:根据订单号更改订单状态。 点卡或充值时注意表单的重复提交问题。 47 | if("2".equals(r9_BType)){ 48 | out.write("success"); 49 | } 50 | 51 | //更改订单的状态 52 | /*Order order=s.findOrderByNum(r6_Order); 53 | order.setStatus(1); //1表示已付款,0表示未付款 54 | s.updateOrder(order);*/ 55 | s.changeOrderStatus(1, r6_Order); 56 | request.getSession().removeAttribute("cart"); 57 | response.setHeader("Refresh", "2;URL="+request.getContextPath()); 58 | } 59 | } 60 | } 61 | 62 | 63 | public void doPost(HttpServletRequest request, HttpServletResponse response) 64 | throws ServletException, IOException { 65 | 66 | doGet(request,response); 67 | 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/cn/tf/dao/BookDao.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao; 2 | 3 | import java.util.List; 4 | 5 | import cn.tf.domain.Book; 6 | 7 | public interface BookDao { 8 | 9 | void addBook(Book book); 10 | 11 | int getTotalRecordsNum(); 12 | 13 | List findPageBooks(int startIndex,int size); 14 | 15 | int getTotalRecordsNum(String categoryId); 16 | 17 | List findPageBooks(int startIndex, int pageSize, String categoryId); 18 | 19 | Book findOne(String bookId); 20 | 21 | 22 | 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/cn/tf/dao/CategoryDao.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao; 2 | 3 | import java.util.List; 4 | 5 | import cn.tf.domain.Category; 6 | 7 | public interface CategoryDao { 8 | 9 | void save(Category category); 10 | 11 | List findAll(); 12 | 13 | Category findByName(String categoryName); 14 | 15 | void deleteByName(String categoryName); 16 | 17 | Category findOne(String categoryId); 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/cn/tf/dao/CustomerDao.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao; 2 | 3 | import cn.tf.domain.Customer; 4 | 5 | public interface CustomerDao { 6 | 7 | void save(Customer customer); 8 | 9 | void update(Customer customer); 10 | 11 | Customer findByCode(String code); 12 | 13 | Customer find(String username, String password); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/cn/tf/dao/OrderDao.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao; 2 | 3 | import java.util.List; 4 | 5 | import cn.tf.domain.Order; 6 | import cn.tf.domain.OrderItem; 7 | 8 | public interface OrderDao { 9 | 10 | void save(Order order); 11 | 12 | Order findByNum(String ordernum); 13 | 14 | void update(Order order); 15 | 16 | //订单号降序排序 17 | List findByCustomerId(String customerId); 18 | 19 | 20 | List findOrderItem(String ordernum); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/cn/tf/dao/PrivilegeDao.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao; 2 | 3 | import java.util.List; 4 | 5 | import cn.tf.domain.Function; 6 | import cn.tf.domain.Role; 7 | import cn.tf.domain.User; 8 | 9 | public interface PrivilegeDao { 10 | 11 | User findUser(String username, String password); 12 | 13 | List findUserRoles(User user); 14 | 15 | List findRoleFunctions(Role role); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/cn/tf/dao/impl/BookDaoImpl.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao.impl; 2 | 3 | import java.sql.SQLException; 4 | import java.util.List; 5 | 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | import org.apache.commons.dbutils.handlers.BeanListHandler; 9 | import org.apache.commons.dbutils.handlers.ScalarHandler; 10 | 11 | import cn.tf.dao.BookDao; 12 | import cn.tf.domain.Book; 13 | import cn.tf.domain.Category; 14 | import cn.tf.utils.C3P0Util; 15 | 16 | public class BookDaoImpl implements BookDao { 17 | 18 | private QueryRunner qr=new QueryRunner(C3P0Util.getDataSource()); 19 | @Override 20 | public void addBook(Book book) { 21 | try { 22 | qr.update("insert into books(id,name,author,price,path,filename,des,categoryId) values (?,?,?,?,?,?,?,?)", 23 | book.getId(),book.getName(),book.getAuthor(),book.getPrice(),book.getPath(), 24 | book.getFilename(),book.getDes(),book.getCategory()==null?null:book.getCategory().getId()); 25 | } catch (SQLException e) { 26 | throw new RuntimeException(e); 27 | } 28 | 29 | } 30 | @Override 31 | public int getTotalRecordsNum() { 32 | 33 | try { 34 | Long num=(Long) qr.query("select count(id) from books ",new ScalarHandler(1)); 35 | return num.intValue(); 36 | 37 | } catch (SQLException e) { 38 | throw new RuntimeException(e); 39 | } 40 | } 41 | 42 | @Override 43 | public List findPageBooks(int startIndex, int size) { 44 | 45 | try { 46 | List books=qr.query("select * from books limit ?,? ",new BeanListHandler(Book.class),startIndex,size); 47 | if(books!=null){ 48 | for (Book book : books) { 49 | String sql = "select * from categorys where id=(select categoryId from books where id=?)"; 50 | Category category = qr.query(sql, new BeanHandler(Category.class), book.getId()); 51 | book.setCategory(category); 52 | } 53 | } 54 | return books; 55 | } catch (SQLException e) { 56 | throw new RuntimeException(e); 57 | } 58 | } 59 | @Override 60 | public int getTotalRecordsNum(String categoryId) { 61 | try { 62 | Long num=(Long) qr.query("select count(id) from books where categoryId=? ",new ScalarHandler(1),categoryId); 63 | return num.intValue(); 64 | 65 | } catch (SQLException e) { 66 | throw new RuntimeException(e); 67 | } 68 | 69 | } 70 | @Override 71 | public List findPageBooks(int startIndex, int pageSize, 72 | String categoryId) { 73 | 74 | try { 75 | List books=qr.query("select * from books where categoryId=? limit ?,? ",new BeanListHandler(Book.class),categoryId,startIndex,pageSize); 76 | if(books!=null){ 77 | for (Book book : books) { 78 | String sql = "select * from categorys where id=?"; 79 | Category category = qr.query(sql, new BeanHandler(Category.class),categoryId); 80 | book.setCategory(category); 81 | } 82 | } 83 | return books; 84 | } catch (SQLException e) { 85 | throw new RuntimeException(e); 86 | } 87 | } 88 | 89 | 90 | //根据多的查少的 91 | @Override 92 | public Book findOne(String bookId) { 93 | 94 | try { 95 | Book book = qr.query("select * from books where id=?", new BeanHandler(Book.class), bookId); 96 | if(book!=null){ 97 | String sql = "select * from categorys where id=(select categoryId from books where id=?)"; 98 | Category category = qr.query(sql, new BeanHandler(Category.class), book.getId()); 99 | book.setCategory(category); 100 | } 101 | return book; 102 | } catch (SQLException e) { 103 | throw new RuntimeException(e); 104 | } 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/cn/tf/dao/impl/CategoryDaoImpl.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao.impl; 2 | 3 | import java.sql.SQLException; 4 | import java.util.List; 5 | 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | import org.apache.commons.dbutils.handlers.BeanListHandler; 9 | 10 | import cn.tf.dao.CategoryDao; 11 | import cn.tf.domain.Category; 12 | import cn.tf.utils.C3P0Util; 13 | 14 | public class CategoryDaoImpl implements CategoryDao { 15 | 16 | 17 | private QueryRunner qr=new QueryRunner(C3P0Util.getDataSource()); 18 | 19 | @Override 20 | public void save(Category category) { 21 | try { 22 | qr.update("insert into categorys(id ,name,des) values(?,?,?)", 23 | category.getId(),category.getName(),category.getDes()); 24 | } catch (SQLException e) { 25 | throw new RuntimeException(e); 26 | } 27 | 28 | } 29 | 30 | @Override 31 | public List findAll() { 32 | try { 33 | return qr.query("select * from categorys", new BeanListHandler(Category.class)); 34 | } catch (SQLException e) { 35 | throw new RuntimeException(e); 36 | } 37 | 38 | 39 | } 40 | 41 | @Override 42 | public Category findByName(String categoryName) { 43 | 44 | try { 45 | return qr.query("select * from categorys where name=? ", new BeanHandler(Category.class),categoryName); 46 | } catch (SQLException e) { 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | 51 | @Override 52 | public void deleteByName(String categoryName) { 53 | 54 | try { 55 | qr.update("delete from categorys where name=? ", categoryName); 56 | } catch (SQLException e) { 57 | throw new RuntimeException(e); 58 | } 59 | 60 | } 61 | 62 | @Override 63 | public Category findOne(String categoryId) { 64 | 65 | try { 66 | return qr.query("select * from categorys where id=? ", new BeanHandler(Category.class),categoryId); 67 | } catch (SQLException e) { 68 | throw new RuntimeException(e); 69 | } 70 | } 71 | 72 | 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/cn/tf/dao/impl/CustomerDaoImpl.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao.impl; 2 | 3 | import java.sql.SQLException; 4 | 5 | import org.apache.commons.dbutils.QueryRunner; 6 | import org.apache.commons.dbutils.handlers.BeanHandler; 7 | 8 | import cn.tf.dao.CustomerDao; 9 | import cn.tf.domain.Customer; 10 | import cn.tf.utils.C3P0Util; 11 | 12 | public class CustomerDaoImpl implements CustomerDao { 13 | 14 | private QueryRunner qr=new QueryRunner(C3P0Util.getDataSource()); 15 | 16 | public void save(Customer customer) { 17 | try { 18 | qr.update("insert into customers (id,username,password,phone,address,email,code,actived) values (?,?,?,?,?,?,?,?)", 19 | customer.getId(),customer.getUsername(),customer.getPassword(),customer.getPhone(),customer.getAddress(), 20 | customer.getEmail(),customer.getCode(),customer.isActived()); 21 | } catch (SQLException e) { 22 | throw new RuntimeException(e); 23 | } 24 | } 25 | 26 | 27 | public void update(Customer customer) { 28 | try { 29 | qr.update("update customers set username=?,password=?,phone=?,address=?,email=?,code=?,actived=? where id=?", 30 | customer.getUsername(),customer.getPassword(),customer.getPhone(),customer.getAddress(), 31 | customer.getEmail(),customer.getCode(),customer.isActived(),customer.getId()); 32 | } catch (SQLException e) { 33 | throw new RuntimeException(e); 34 | } 35 | } 36 | 37 | public Customer findByCode(String code) { 38 | try { 39 | return qr.query("select * from customers where code=?", new BeanHandler(Customer.class),code); 40 | } catch (SQLException e) { 41 | throw new RuntimeException(e); 42 | } 43 | } 44 | 45 | public Customer find(String username, String password) { 46 | try { 47 | return qr.query("select * from customers where username=? and password=?", new BeanHandler(Customer.class),username,password); 48 | } catch (SQLException e) { 49 | throw new RuntimeException(e); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/cn/tf/dao/impl/OrderDaoImpl.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao.impl; 2 | 3 | import java.sql.SQLException; 4 | import java.util.List; 5 | 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | import org.apache.commons.dbutils.handlers.BeanListHandler; 9 | 10 | import cn.tf.dao.OrderDao; 11 | import cn.tf.domain.Book; 12 | import cn.tf.domain.Customer; 13 | import cn.tf.domain.Order; 14 | import cn.tf.domain.OrderItem; 15 | import cn.tf.utils.C3P0Util; 16 | 17 | public class OrderDaoImpl implements OrderDao { 18 | 19 | private QueryRunner qr=new QueryRunner(C3P0Util.getDataSource()); 20 | 21 | //保存订单 22 | @Override 23 | public void save(Order order) { 24 | 25 | try { 26 | qr.update("insert into orders (ordernum,price,number,status,customerId) values (?,?,?,?,?)", 27 | order.getOrdernum(),order.getPrice(),order.getNumber(),order.getStatus(), 28 | order.getCustomer()==null?null:order.getCustomer().getId()); 29 | List items = order.getItems(); 30 | for(OrderItem item:items){ 31 | qr.update("insert into orderitems (id,number,price,ordernum,bookid) values (?,?,?,?,?)", 32 | item.getId(),item.getNumber(),item.getPrice(),order.getOrdernum(),item.getBook()==null?null:item.getBook().getId()); 33 | } 34 | } catch (SQLException e) { 35 | throw new RuntimeException(e); 36 | } 37 | } 38 | 39 | 40 | public Order findByNum(String ordernum) { 41 | try { 42 | Order order = qr.query("select * from orders where ordernum=?", new BeanHandler(Order.class), ordernum); 43 | if(order!=null){ 44 | Customer customer = qr.query("select * from customers where id=(select customerId from orders where ordernum=?)", new BeanHandler(Customer.class), ordernum); 45 | order.setCustomer(customer); 46 | } 47 | return order; 48 | } catch (SQLException e) { 49 | throw new RuntimeException(e); 50 | } 51 | } 52 | public void update(Order order) { 53 | try { 54 | qr.update("update orders set price=?,number=?,status=? where ordernum=?", order.getPrice(),order.getNumber(),order.getStatus(),order.getOrdernum()); 55 | } catch (SQLException e) { 56 | throw new RuntimeException(e); 57 | } 58 | } 59 | 60 | 61 | @Override 62 | public List findByCustomerId(String customerId) { 63 | try { 64 | List orders=qr.query("select * from orders where customerId=? order by ordernum desc ", new BeanListHandler(Order.class),customerId); 65 | if(orders!=null){ 66 | Customer customer=qr.query("select * from customers where id=? ",new BeanHandler(Customer.class),customerId); 67 | for (Order order : orders) { 68 | order.setCustomer(customer); 69 | } 70 | } 71 | return orders; 72 | } catch (SQLException e) { 73 | throw new RuntimeException(e); 74 | } 75 | } 76 | 77 | 78 | @Override 79 | public List findOrderItem(String ordernum) { 80 | 81 | try { 82 | List items = qr.query("select * from orderitems where ordernum=?", new BeanListHandler(OrderItem.class), ordernum); 83 | if(items!=null){ 84 | for(OrderItem o:items){ 85 | Book book = qr.query("select * from books where id=(select bookId from orderitems where id=?)", new BeanHandler(Book.class), o.getId()); 86 | o.setBook(book); 87 | } 88 | } 89 | return items; 90 | } catch (SQLException e) { 91 | throw new RuntimeException(e); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/cn/tf/dao/impl/PrivilegeDaoImpl.java: -------------------------------------------------------------------------------- 1 | package cn.tf.dao.impl; 2 | 3 | import java.sql.SQLException; 4 | import java.util.List; 5 | 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | import org.apache.commons.dbutils.handlers.BeanListHandler; 9 | 10 | import cn.tf.dao.PrivilegeDao; 11 | import cn.tf.domain.Function; 12 | import cn.tf.domain.Role; 13 | import cn.tf.domain.User; 14 | import cn.tf.utils.C3P0Util; 15 | 16 | public class PrivilegeDaoImpl implements PrivilegeDao { 17 | 18 | private QueryRunner qr = new QueryRunner(C3P0Util.getDataSource()); 19 | 20 | @Override 21 | public User findUser(String username, String password) { 22 | 23 | try { 24 | return qr.query( 25 | "select * from users where username=? and password=?", 26 | new BeanHandler(User.class), username, password); 27 | } catch (SQLException e) { 28 | throw new RuntimeException(e); 29 | } 30 | } 31 | 32 | public List findUserRoles(User user) { 33 | try { 34 | return qr.query("select * from roles where id in (select r_id from user_role where u_id=?)", new BeanListHandler(Role.class), user.getId()); 35 | } catch (SQLException e) { 36 | throw new RuntimeException(e); 37 | } 38 | } 39 | public List findRoleFunctions(Role role) { 40 | try { 41 | return qr.query("select * from functions where id in (select f_id from role_function where r_id=?)", new BeanListHandler(Function.class), role.getId()); 42 | } catch (SQLException e) { 43 | throw new RuntimeException(e); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/cn/tf/domain/Book.java: -------------------------------------------------------------------------------- 1 | package cn.tf.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Book implements Serializable { 6 | 7 | private String id; 8 | private String name; 9 | private String author; 10 | private float price; 11 | private String path; // image的存放路径 12 | private String filename; // image的文件名 13 | private String des; 14 | 15 | private Category category; 16 | //private String categoryId; //书籍所属的分类id 17 | 18 | public String getId() { 19 | return id; 20 | } 21 | 22 | public void setId(String id) { 23 | this.id = id; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getAuthor() { 35 | return author; 36 | } 37 | 38 | public void setAuthor(String author) { 39 | this.author = author; 40 | } 41 | 42 | public float getPrice() { 43 | return price; 44 | } 45 | 46 | public void setPrice(float price) { 47 | this.price = price; 48 | } 49 | 50 | public String getPath() { 51 | return path; 52 | } 53 | 54 | public void setPath(String path) { 55 | this.path = path; 56 | } 57 | 58 | public String getFilename() { 59 | return filename; 60 | } 61 | 62 | public void setFilename(String filename) { 63 | this.filename = filename; 64 | } 65 | 66 | public String getDes() { 67 | return des; 68 | } 69 | 70 | public void setDes(String des) { 71 | this.des = des; 72 | } 73 | 74 | public Category getCategory() { 75 | return category; 76 | } 77 | 78 | public void setCategory(Category category) { 79 | this.category = category; 80 | } 81 | 82 | public Book(Category category) { 83 | this.category = category; 84 | } 85 | 86 | public Book() { 87 | super(); 88 | } 89 | 90 | 91 | 92 | 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/cn/tf/domain/Category.java: -------------------------------------------------------------------------------- 1 | package cn.tf.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Category implements Serializable{ 6 | 7 | private String id; //分类号 8 | private String name; //分类名 9 | private String des; //描述 10 | public String getId() { 11 | return id; 12 | } 13 | public void setId(String id) { 14 | this.id = id; 15 | } 16 | public String getName() { 17 | return name; 18 | } 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | public String getDes() { 23 | return des; 24 | } 25 | public void setDes(String des) { 26 | this.des = des; 27 | } 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/cn/tf/domain/Customer.java: -------------------------------------------------------------------------------- 1 | package cn.tf.domain; 2 | 3 | public class Customer { 4 | 5 | private String id; 6 | private String username; 7 | private String password; 8 | private String phone; 9 | private String address; 10 | private String email; 11 | 12 | private String code; //激活码 13 | private boolean actived; //账户是否激活 14 | public String getId() { 15 | return id; 16 | } 17 | public void setId(String id) { 18 | this.id = id; 19 | } 20 | public String getUsername() { 21 | return username; 22 | } 23 | public void setUsername(String username) { 24 | this.username = username; 25 | } 26 | public String getPassword() { 27 | return password; 28 | } 29 | public void setPassword(String password) { 30 | this.password = password; 31 | } 32 | public String getPhone() { 33 | return phone; 34 | } 35 | public void setPhone(String photo) { 36 | this.phone = photo; 37 | } 38 | public String getAddress() { 39 | return address; 40 | } 41 | public void setAddress(String address) { 42 | this.address = address; 43 | } 44 | public String getEmail() { 45 | return email; 46 | } 47 | public void setEmail(String email) { 48 | this.email = email; 49 | } 50 | public String getCode() { 51 | return code; 52 | } 53 | public void setCode(String code) { 54 | this.code = code; 55 | } 56 | public boolean isActived() { 57 | return actived; 58 | } 59 | public void setActived(boolean actived) { 60 | this.actived = actived; 61 | } 62 | 63 | 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/cn/tf/domain/Function.java: -------------------------------------------------------------------------------- 1 | package cn.tf.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Function implements Serializable{ 6 | 7 | private String id; 8 | private String name; 9 | private String uri; 10 | public String getId() { 11 | return id; 12 | } 13 | public void setId(String id) { 14 | this.id = id; 15 | } 16 | public String getName() { 17 | return name; 18 | } 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | public String getUri() { 23 | return uri; 24 | } 25 | public void setUri(String uri) { 26 | this.uri = uri; 27 | } 28 | @Override 29 | public int hashCode() { 30 | final int prime = 31; 31 | int result = 1; 32 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 33 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 34 | result = prime * result + ((uri == null) ? 0 : uri.hashCode()); 35 | return result; 36 | } 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | Function other = (Function) obj; 46 | if (id == null) { 47 | if (other.id != null) 48 | return false; 49 | } else if (!id.equals(other.id)) 50 | return false; 51 | if (name == null) { 52 | if (other.name != null) 53 | return false; 54 | } else if (!name.equals(other.name)) 55 | return false; 56 | if (uri == null) { 57 | if (other.uri != null) 58 | return false; 59 | } else if (!uri.equals(other.uri)) 60 | return false; 61 | return true; 62 | } 63 | 64 | 65 | 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/cn/tf/domain/Order.java: -------------------------------------------------------------------------------- 1 | package cn.tf.domain; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class Order implements Serializable{ 8 | 9 | private String ordernum; 10 | private float price; 11 | private int number; 12 | private int status; 13 | 14 | private Customer customer; 15 | private List items=new ArrayList(); 16 | 17 | 18 | public String getOrdernum() { 19 | return ordernum; 20 | } 21 | 22 | public void setOrdernum(String ordernum) { 23 | this.ordernum = ordernum; 24 | } 25 | 26 | public float getPrice() { 27 | return price; 28 | } 29 | 30 | public void setPrice(float price) { 31 | this.price = price; 32 | } 33 | 34 | public int getNumber() { 35 | return number; 36 | } 37 | 38 | public void setNumber(int number) { 39 | this.number = number; 40 | } 41 | 42 | public int getStatus() { 43 | return status; 44 | } 45 | 46 | public void setStatus(int status) { 47 | this.status = status; 48 | } 49 | 50 | public Customer getCustomer() { 51 | return customer; 52 | } 53 | 54 | public void setCustomer(Customer customer) { 55 | this.customer = customer; 56 | } 57 | 58 | 59 | 60 | public List getItems() { 61 | return items; 62 | } 63 | 64 | public void setItems(List items) { 65 | this.items = items; 66 | } 67 | 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/cn/tf/domain/OrderItem.java: -------------------------------------------------------------------------------- 1 | package cn.tf.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | public class OrderItem implements Serializable { 6 | 7 | private String id; 8 | private int number; 9 | private float price; 10 | private Book book; 11 | public String getId() { 12 | return id; 13 | } 14 | public void setId(String id) { 15 | this.id = id; 16 | } 17 | public int getNumber() { 18 | return number; 19 | } 20 | public void setNumber(int number) { 21 | this.number = number; 22 | } 23 | public float getPrice() { 24 | return price; 25 | } 26 | public void setPrice(float price) { 27 | this.price = price; 28 | } 29 | public Book getBook() { 30 | return book; 31 | } 32 | public void setBook(Book book) { 33 | this.book = book; 34 | } 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/cn/tf/domain/Role.java: -------------------------------------------------------------------------------- 1 | package cn.tf.domain; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class Role implements Serializable{ 8 | 9 | private String id; 10 | private String name; 11 | private String description; 12 | private List functions = new ArrayList(); 13 | public String getId() { 14 | return id; 15 | } 16 | public void setId(String id) { 17 | this.id = id; 18 | } 19 | public String getName() { 20 | return name; 21 | } 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | public String getDescription() { 26 | return description; 27 | } 28 | public void setDescription(String description) { 29 | this.description = description; 30 | } 31 | public List getFunctions() { 32 | return functions; 33 | } 34 | public void setFunctions(List functions) { 35 | this.functions = functions; 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/cn/tf/domain/User.java: -------------------------------------------------------------------------------- 1 | package cn.tf.domain; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class User implements Serializable{ 8 | 9 | private String id; 10 | private String username; 11 | private String password; 12 | 13 | private List roles = new ArrayList(); 14 | 15 | public String getId() { 16 | return id; 17 | } 18 | 19 | public void setId(String id) { 20 | this.id = id; 21 | } 22 | 23 | public String getUsername() { 24 | return username; 25 | } 26 | 27 | public void setUsername(String username) { 28 | this.username = username; 29 | } 30 | 31 | public String getPassword() { 32 | return password; 33 | } 34 | 35 | public void setPassword(String password) { 36 | this.password = password; 37 | } 38 | 39 | public List getRoles() { 40 | return roles; 41 | } 42 | 43 | public void setRoles(List roles) { 44 | this.roles = roles; 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/cn/tf/filter/CharseEncodingFilter.java: -------------------------------------------------------------------------------- 1 | package cn.tf.filter; 2 | 3 | import java.io.IOException; 4 | import java.io.UnsupportedEncodingException; 5 | 6 | import javax.servlet.Filter; 7 | import javax.servlet.FilterChain; 8 | import javax.servlet.FilterConfig; 9 | import javax.servlet.ServletException; 10 | import javax.servlet.ServletRequest; 11 | import javax.servlet.ServletResponse; 12 | import javax.servlet.annotation.WebFilter; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletRequestWrapper; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | @WebFilter(filterName="CharseEncodingFilter" ,urlPatterns="/*") 18 | public class CharseEncodingFilter implements Filter { 19 | 20 | 21 | 22 | private FilterConfig filterConfig; 23 | 24 | @Override 25 | public void destroy() { 26 | } 27 | 28 | @Override 29 | public void doFilter(ServletRequest req, ServletResponse resp, 30 | FilterChain chain) throws IOException, ServletException { 31 | HttpServletRequest request; 32 | HttpServletResponse response; 33 | try { 34 | request=(HttpServletRequest) req; 35 | response=(HttpServletResponse) resp; 36 | } catch (Exception e) { 37 | throw new RuntimeException(e); 38 | } 39 | String encoding=filterConfig.getInitParameter("encoding"); 40 | if(encoding==null) 41 | encoding="UTF-8"; 42 | 43 | response.setCharacterEncoding(encoding); 44 | response.setContentType("text/html;charset="+encoding); 45 | request.setCharacterEncoding(encoding); 46 | 47 | GetHttpServletRequest getrequest = new GetHttpServletRequest(request); 48 | chain.doFilter(getrequest, response); 49 | 50 | } 51 | 52 | @Override 53 | public void init(FilterConfig filterConfig) throws ServletException { 54 | this.filterConfig=filterConfig; 55 | } 56 | } 57 | 58 | class GetHttpServletRequest extends HttpServletRequestWrapper{ 59 | public GetHttpServletRequest(HttpServletRequest request){ 60 | super(request); 61 | } 62 | 63 | public String getParameter(String name) { 64 | String value = super.getParameter(name); 65 | if(value==null) 66 | return value; 67 | //获取请求方式 68 | String method = super.getMethod(); 69 | if("get".equalsIgnoreCase(method)){ 70 | try { 71 | value = new String(value.getBytes("ISO-8859-1"),super.getCharacterEncoding()); 72 | } catch (UnsupportedEncodingException e) { 73 | e.printStackTrace(); 74 | } 75 | } 76 | return value; 77 | } 78 | 79 | } 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/cn/tf/filter/PrivilegeFilter.java: -------------------------------------------------------------------------------- 1 | package cn.tf.filter; 2 | 3 | import java.io.IOException; 4 | import java.util.HashSet; 5 | import java.util.List; 6 | import java.util.Set; 7 | 8 | import javax.servlet.Filter; 9 | import javax.servlet.FilterChain; 10 | import javax.servlet.FilterConfig; 11 | import javax.servlet.ServletException; 12 | import javax.servlet.ServletRequest; 13 | import javax.servlet.ServletResponse; 14 | import javax.servlet.annotation.WebFilter; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | 18 | import cn.tf.domain.Function; 19 | import cn.tf.domain.Role; 20 | import cn.tf.domain.User; 21 | import cn.tf.service.PrivilegeService; 22 | import cn.tf.service.impl.PrivilegeServiceImpl; 23 | import cn.tf.utils.Constant; 24 | 25 | 26 | @WebFilter(filterName="PrivilegeFilter" ,urlPatterns="/manage/*") 27 | public class PrivilegeFilter implements Filter { 28 | private PrivilegeService ps = new PrivilegeServiceImpl(); 29 | public void init(FilterConfig filterConfig) throws ServletException { 30 | 31 | } 32 | 33 | public void doFilter(ServletRequest req, ServletResponse res, 34 | FilterChain chain) throws IOException, ServletException { 35 | HttpServletRequest request; 36 | HttpServletResponse response; 37 | try { 38 | request = (HttpServletRequest) req; 39 | response = (HttpServletResponse) res; 40 | } catch (ClassCastException e) { 41 | throw new ServletException(e); 42 | } 43 | 44 | User user = (User) request.getSession().getAttribute(Constant.USER_LOGIN_FLAG); 45 | //没有登录,则重定向到登录页面 46 | if(user==null){ 47 | response.sendRedirect(request.getContextPath()+"/passport/login.jsp"); 48 | return; 49 | } 50 | //登录了 51 | Set functions = new HashSet(); 52 | 53 | List roles = ps.findUserRoles(user); 54 | 55 | for(Role role:roles){ 56 | List funs = ps.findRoleFunctions(role); 57 | functions.addAll(funs); 58 | } 59 | 60 | //获取用户访问的uri 61 | String uri = request.getRequestURI(); 62 | String queryString = request.getQueryString(); 63 | String fullUri = uri+(queryString==null?"":("?"+queryString)); 64 | 65 | //查看uri在不在访问的范围内 66 | boolean hasPermission = false; 67 | for(Function fun:functions){ 68 | if(fullUri.startsWith(fun.getUri())){ 69 | hasPermission = true; 70 | break; 71 | } 72 | } 73 | 74 | if(!hasPermission){ 75 | response.getWriter().write("权限拒绝"); 76 | return; 77 | } 78 | //放行 79 | chain.doFilter(request, response); 80 | } 81 | 82 | public void destroy() { 83 | 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/cn/tf/service/BusinessService.java: -------------------------------------------------------------------------------- 1 | package cn.tf.service; 2 | 3 | import java.util.List; 4 | 5 | import cn.tf.commons.Page; 6 | import cn.tf.domain.Book; 7 | import cn.tf.domain.Category; 8 | import cn.tf.domain.Customer; 9 | import cn.tf.domain.Order; 10 | import cn.tf.domain.OrderItem; 11 | 12 | public interface BusinessService { 13 | 14 | //添加分类 15 | void addCategory(Category category); 16 | 17 | //查询分类 18 | List findAllCategories(); 19 | 20 | //根据分类名称查询该分类是否可用 21 | boolean isCategoryExists(String categoryName); 22 | 23 | 24 | void delCategory(String categoryName); 25 | 26 | 27 | //添加书籍信息 28 | void addBook(Book book); 29 | 30 | 31 | //根据分类id查询分类信息 32 | Category findCategoryById(String categoryId); 33 | 34 | 35 | 36 | //根据用户要查看的页码,返回封装了所有分页信息的page对象 37 | Page findPage(String num); 38 | 39 | 40 | //根据用户要查看的页码和种类,返回封装了所有分页信息的page对象 41 | Page findPage(String num, String categoryId); 42 | 43 | 44 | Book findBookById(String bookId); 45 | 46 | //用户注册 47 | void registCustomer(Customer customer); 48 | 49 | 50 | //根据激活码获取用户信息 51 | Customer findByCode(String code); 52 | 53 | //激活客户的账户 54 | void activeCustomer(Customer customer); 55 | 56 | //根据用户名或密码登录,如果账户没有激活就返回null 57 | Customer login(String username,String password); 58 | 59 | //生成订单 60 | void genOrder(Order order); 61 | 62 | //根据订单号查找订单 63 | Order findOrderByNum(String ordernum); 64 | 65 | //更新订单信息 66 | void updateOrder(Order order); 67 | 68 | //更新订单状态 69 | void changeOrderStatus(int status,String ordernum); 70 | 71 | // 72 | List findOrdersByCustomerId(String customerId); 73 | 74 | List findOrderItemByCustomerId(String ordernum); 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/cn/tf/service/PrivilegeService.java: -------------------------------------------------------------------------------- 1 | package cn.tf.service; 2 | 3 | import java.util.List; 4 | 5 | import cn.tf.domain.Function; 6 | import cn.tf.domain.Role; 7 | import cn.tf.domain.User; 8 | 9 | public interface PrivilegeService { 10 | 11 | User login(String username, String password); 12 | //查询用户的所有角色 13 | List findUserRoles(User user); 14 | 15 | List findRoleFunctions(Role role); 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/cn/tf/service/impl/BusinessServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.tf.service.impl; 2 | 3 | import java.util.List; 4 | import java.util.UUID; 5 | 6 | import cn.tf.commons.Page; 7 | import cn.tf.dao.BookDao; 8 | import cn.tf.dao.CategoryDao; 9 | import cn.tf.dao.CustomerDao; 10 | import cn.tf.dao.OrderDao; 11 | import cn.tf.dao.impl.BookDaoImpl; 12 | import cn.tf.dao.impl.CategoryDaoImpl; 13 | import cn.tf.dao.impl.CustomerDaoImpl; 14 | import cn.tf.dao.impl.OrderDaoImpl; 15 | import cn.tf.domain.Book; 16 | import cn.tf.domain.Category; 17 | import cn.tf.domain.Customer; 18 | import cn.tf.domain.Order; 19 | import cn.tf.domain.OrderItem; 20 | import cn.tf.service.BusinessService; 21 | 22 | public class BusinessServiceImpl implements BusinessService { 23 | 24 | private CategoryDao categoryDao=new CategoryDaoImpl(); 25 | private CustomerDao customerDao=new CustomerDaoImpl(); 26 | private OrderDao orderDao=new OrderDaoImpl(); 27 | 28 | private BookDao bookDao=new BookDaoImpl(); 29 | @Override 30 | public void addCategory(Category category){// TODO Auto-generated method stub 31 | category.setId(UUID.randomUUID().toString()); 32 | categoryDao.save(category); 33 | } 34 | 35 | @Override 36 | public List findAllCategories() { 37 | 38 | return categoryDao.findAll(); 39 | } 40 | 41 | @Override 42 | public boolean isCategoryExists(String categoryName) { 43 | Category category=categoryDao.findByName(categoryName); 44 | return category==null?false:true; 45 | } 46 | 47 | @Override 48 | public void delCategory(String categoryName) { 49 | categoryDao.deleteByName(categoryName); 50 | 51 | } 52 | 53 | @Override 54 | public void addBook(Book book) { 55 | if(book==null) 56 | throw new IllegalArgumentException("error"); 57 | if(book.getCategory()==null) 58 | throw new IllegalArgumentException("error"); 59 | book.setId(UUID.randomUUID().toString()); 60 | bookDao.addBook(book); 61 | 62 | } 63 | 64 | @Override 65 | public Category findCategoryById(String categoryId) { 66 | 67 | return categoryDao.findOne(categoryId); 68 | } 69 | 70 | @Override 71 | public Page findPage(String num) { 72 | int pageNum =1; 73 | if(num!=null){ 74 | pageNum=Integer.parseInt(num); 75 | } 76 | int totalRecordsNum=bookDao.getTotalRecordsNum(); 77 | Page page=new Page(pageNum,totalRecordsNum); 78 | List records=bookDao.findPageBooks(page.getStartIndex(), page.getPageSize()); 79 | page.setRecords(records); 80 | 81 | return page; 82 | } 83 | 84 | @Override 85 | public Page findPage(String num, String categoryId) { 86 | int pageNum =1; 87 | if(num!=null){ 88 | pageNum=Integer.parseInt(num); 89 | } 90 | int totalRecordsNum=bookDao.getTotalRecordsNum(categoryId); 91 | Page page=new Page(pageNum,totalRecordsNum); 92 | List records=bookDao.findPageBooks(page.getStartIndex(), page.getPageSize(),categoryId); 93 | page.setRecords(records); 94 | 95 | return page; 96 | } 97 | 98 | @Override 99 | public Book findBookById(String bookId) { 100 | 101 | return bookDao.findOne(bookId); 102 | 103 | } 104 | 105 | @Override 106 | public void registCustomer(Customer customer) { 107 | customer.setId(UUID.randomUUID().toString()); 108 | customerDao.save(customer); 109 | 110 | } 111 | 112 | @Override 113 | public Customer findByCode(String code) { 114 | 115 | return customerDao.findByCode(code); 116 | } 117 | 118 | @Override 119 | public void activeCustomer(Customer customer) { 120 | if(customer==null) 121 | throw new RuntimeException("数据不能为空"); 122 | if(customer.getId()==null) 123 | throw new RuntimeException("更新数据的主键不能为空"); 124 | 125 | customerDao.update(customer); 126 | 127 | } 128 | 129 | @Override 130 | public Customer login(String username, String password) { 131 | 132 | Customer customer = customerDao.find(username,password); 133 | if(customer==null) 134 | return null; 135 | if(!customer.isActived()) 136 | return null; 137 | return customer; 138 | } 139 | 140 | //生成订单 141 | @Override 142 | public void genOrder(Order order) { 143 | if(order==null) 144 | throw new RuntimeException("订单不能为空"); 145 | if(order.getCustomer()==null) 146 | throw new RuntimeException("订单的客户不能为空"); 147 | orderDao.save(order); 148 | 149 | } 150 | 151 | @Override 152 | public Order findOrderByNum(String ordernum) { 153 | 154 | return orderDao.findByNum(ordernum); 155 | } 156 | 157 | @Override 158 | public void updateOrder(Order order) { 159 | orderDao.update(order); 160 | 161 | } 162 | 163 | @Override 164 | public void changeOrderStatus(int status, String ordernum) { 165 | Order order=findOrderByNum(ordernum); 166 | order.setStatus(status); 167 | updateOrder(order); 168 | } 169 | 170 | @Override 171 | public List findOrdersByCustomerId(String customerId) { 172 | 173 | return orderDao.findByCustomerId(customerId); 174 | } 175 | 176 | @Override 177 | public List findOrderItemByCustomerId(String ordernum) { 178 | 179 | return orderDao.findOrderItem(ordernum); 180 | } 181 | 182 | } 183 | -------------------------------------------------------------------------------- /src/cn/tf/service/impl/PrivilegeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.tf.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import cn.tf.dao.PrivilegeDao; 6 | import cn.tf.dao.impl.PrivilegeDaoImpl; 7 | import cn.tf.domain.Function; 8 | import cn.tf.domain.Role; 9 | import cn.tf.domain.User; 10 | import cn.tf.service.PrivilegeService; 11 | 12 | public class PrivilegeServiceImpl implements PrivilegeService { 13 | 14 | private PrivilegeDao dao=new PrivilegeDaoImpl(); 15 | @Override 16 | public User login(String username, String password) { 17 | return dao.findUser(username,password); 18 | } 19 | @Override 20 | public List findUserRoles(User user) { 21 | 22 | return dao.findUserRoles(user); 23 | } 24 | @Override 25 | public List findRoleFunctions(Role role) { 26 | return dao.findRoleFunctions(role); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/cn/tf/utils/C3P0Util.java: -------------------------------------------------------------------------------- 1 | package cn.tf.utils; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | import javax.sql.DataSource; 7 | 8 | import com.mchange.v2.c3p0.ComboPooledDataSource; 9 | 10 | public class C3P0Util { 11 | 12 | private static ComboPooledDataSource dataSource=new ComboPooledDataSource(); 13 | public static DataSource getDataSource(){ 14 | return dataSource; 15 | } 16 | 17 | public static Connection getConnection(){ 18 | try { 19 | return dataSource.getConnection(); 20 | } catch (SQLException e) { 21 | throw new RuntimeException(e); 22 | } 23 | 24 | } 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/cn/tf/utils/Constant.java: -------------------------------------------------------------------------------- 1 | package cn.tf.utils; 2 | 3 | public interface Constant { 4 | String USER_LOGIN_FLAG = "user"; 5 | } 6 | -------------------------------------------------------------------------------- /src/cn/tf/utils/OrderNumUtil.java: -------------------------------------------------------------------------------- 1 | package cn.tf.utils; 2 | 3 | import java.sql.SQLException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | import org.apache.commons.dbutils.QueryRunner; 8 | import org.apache.commons.dbutils.handlers.ScalarHandler; 9 | 10 | //订单生成器 11 | public class OrderNumUtil { 12 | 13 | public static String genOrderNum() { 14 | 15 | //得到当前的日期,用日期去查找是否有对应记录 16 | 17 | QueryRunner qr=new QueryRunner(C3P0Util.getDataSource()); 18 | Date now=new Date(); 19 | SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); 20 | String date=sdf.format(now); 21 | 22 | StringBuffer sb=new StringBuffer(date.replace("-", "")); 23 | 24 | 25 | //没有对应记录,则插入当前日期和数字1 26 | 27 | //有对应记录,则去除数字,返回数字加1,同时更新数据库 28 | try { 29 | Integer num=(Integer) qr.query("select num from ordernum where prefix=? ", new ScalarHandler(1),date); 30 | if(num==null){ 31 | num=new Integer(1); 32 | qr.update("insert into ordernum(prefix, num) values(?,?)",date,num); 33 | 34 | }else{ 35 | num=num+1; 36 | qr.update("update ordernum set num=? where prefix=? ",num,date); 37 | } 38 | 39 | int numLength=num.toString().length(); 40 | for(int i=0;i<11-numLength;i++){ 41 | sb.append("0"); 42 | } 43 | sb.append(num); 44 | return sb.toString(); 45 | } catch (SQLException e) { 46 | 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/cn/tf/utils/PaymentUtil.java: -------------------------------------------------------------------------------- 1 | package cn.tf.utils; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.security.MessageDigest; 5 | import java.security.NoSuchAlgorithmException; 6 | import java.util.Arrays; 7 | 8 | public class PaymentUtil { 9 | 10 | private static String encodingCharset = "UTF-8"; 11 | 12 | /** 13 | * 生成hmac方法 14 | * 15 | * @param p0_Cmd 业务类型 16 | * @param p1_MerId 商户编号 17 | * @param p2_Order 商户订单号 18 | * @param p3_Amt 支付金额 19 | * @param p4_Cur 交易币种 20 | * @param p5_Pid 商品名称 21 | * @param p6_Pcat 商品种类 22 | * @param p7_Pdesc 商品描述 23 | * @param p8_Url 商户接收支付成功数据的地址 24 | * @param p9_SAF 送货地址 25 | * @param pa_MP 商户扩展信息 26 | * @param pd_FrpId 银行编码 27 | * @param pr_NeedResponse 应答机制 28 | * @param keyValue 商户密钥 29 | * @return 30 | */ 31 | public static String buildHmac(String p0_Cmd,String p1_MerId, 32 | String p2_Order, String p3_Amt, String p4_Cur,String p5_Pid, String p6_Pcat, 33 | String p7_Pdesc,String p8_Url, String p9_SAF,String pa_MP,String pd_FrpId, 34 | String pr_NeedResponse,String keyValue) { 35 | StringBuilder sValue = new StringBuilder(); 36 | // 业务类型 37 | sValue.append(p0_Cmd); 38 | // 商户编号 39 | sValue.append(p1_MerId); 40 | // 商户订单号 41 | sValue.append(p2_Order); 42 | // 支付金额 43 | sValue.append(p3_Amt); 44 | // 交易币种 45 | sValue.append(p4_Cur); 46 | // 商品名称 47 | sValue.append(p5_Pid); 48 | // 商品种类 49 | sValue.append(p6_Pcat); 50 | // 商品描述 51 | sValue.append(p7_Pdesc); 52 | // 商户接收支付成功数据的地址 53 | sValue.append(p8_Url); 54 | // 送货地址 55 | sValue.append(p9_SAF); 56 | // 商户扩展信息 57 | sValue.append(pa_MP); 58 | // 银行编码 59 | sValue.append(pd_FrpId); 60 | // 应答机制 61 | sValue.append(pr_NeedResponse); 62 | 63 | return PaymentUtil.hmacSign(sValue.toString(), keyValue); 64 | } 65 | 66 | /** 67 | * 返回校验hmac方法 68 | * 69 | * @param hmac 支付网关发来的加密验证码 70 | * @param p1_MerId 商户编号 71 | * @param r0_Cmd 业务类型 72 | * @param r1_Code 支付结果 73 | * @param r2_TrxId 易宝支付交易流水号 74 | * @param r3_Amt 支付金额 75 | * @param r4_Cur 交易币种 76 | * @param r5_Pid 商品名称 77 | * @param r6_Order 商户订单号 78 | * @param r7_Uid 易宝支付会员ID 79 | * @param r8_MP 商户扩展信息 80 | * @param r9_BType 交易结果返回类型 81 | * @param keyValue 密钥 82 | * @return 83 | */ 84 | public static boolean verifyCallback(String hmac, String p1_MerId, 85 | String r0_Cmd, String r1_Code, String r2_TrxId, String r3_Amt, 86 | String r4_Cur, String r5_Pid, String r6_Order, String r7_Uid, 87 | String r8_MP, String r9_BType, String keyValue) { 88 | StringBuilder sValue = new StringBuilder(); 89 | // 商户编号 90 | sValue.append(p1_MerId); 91 | // 业务类型 92 | sValue.append(r0_Cmd); 93 | // 支付结果 94 | sValue.append(r1_Code); 95 | // 易宝支付交易流水号 96 | sValue.append(r2_TrxId); 97 | // 支付金额 98 | sValue.append(r3_Amt); 99 | // 交易币种 100 | sValue.append(r4_Cur); 101 | // 商品名称 102 | sValue.append(r5_Pid); 103 | // 商户订单号 104 | sValue.append(r6_Order); 105 | // 易宝支付会员ID 106 | sValue.append(r7_Uid); 107 | // 商户扩展信息 108 | sValue.append(r8_MP); 109 | // 交易结果返回类型 110 | sValue.append(r9_BType); 111 | String sNewString = PaymentUtil.hmacSign(sValue.toString(), keyValue); 112 | return sNewString.equals(hmac); 113 | } 114 | 115 | /** 116 | * @param aValue 117 | * @param aKey 118 | * @return 119 | */ 120 | public static String hmacSign(String aValue, String aKey) { 121 | byte k_ipad[] = new byte[64]; 122 | byte k_opad[] = new byte[64]; 123 | byte keyb[]; 124 | byte value[]; 125 | try { 126 | keyb = aKey.getBytes(encodingCharset); 127 | value = aValue.getBytes(encodingCharset); 128 | } catch (UnsupportedEncodingException e) { 129 | keyb = aKey.getBytes(); 130 | value = aValue.getBytes(); 131 | } 132 | 133 | Arrays.fill(k_ipad, keyb.length, 64, (byte) 54); 134 | Arrays.fill(k_opad, keyb.length, 64, (byte) 92); 135 | for (int i = 0; i < keyb.length; i++) { 136 | k_ipad[i] = (byte) (keyb[i] ^ 0x36); 137 | k_opad[i] = (byte) (keyb[i] ^ 0x5c); 138 | } 139 | 140 | MessageDigest md = null; 141 | try { 142 | md = MessageDigest.getInstance("MD5"); 143 | } catch (NoSuchAlgorithmException e) { 144 | 145 | return null; 146 | } 147 | md.update(k_ipad); 148 | md.update(value); 149 | byte dg[] = md.digest(); 150 | md.reset(); 151 | md.update(k_opad); 152 | md.update(dg, 0, 16); 153 | dg = md.digest(); 154 | return toHex(dg); 155 | } 156 | 157 | public static String toHex(byte input[]) { 158 | if (input == null) 159 | return null; 160 | StringBuffer output = new StringBuffer(input.length * 2); 161 | for (int i = 0; i < input.length; i++) { 162 | int current = input[i] & 0xff; 163 | if (current < 16) 164 | output.append("0"); 165 | output.append(Integer.toString(current, 16)); 166 | } 167 | 168 | return output.toString(); 169 | } 170 | 171 | /** 172 | * 173 | * @param args 174 | * @param key 175 | * @return 176 | */ 177 | public static String getHmac(String[] args, String key) { 178 | if (args == null || args.length == 0) { 179 | return (null); 180 | } 181 | StringBuffer str = new StringBuffer(); 182 | for (int i = 0; i < args.length; i++) { 183 | str.append(args[i]); 184 | } 185 | return (hmacSign(str.toString(), key)); 186 | } 187 | 188 | /** 189 | * @param aValue 190 | * @return 191 | */ 192 | public static String digest(String aValue) { 193 | aValue = aValue.trim(); 194 | byte value[]; 195 | try { 196 | value = aValue.getBytes(encodingCharset); 197 | } catch (UnsupportedEncodingException e) { 198 | value = aValue.getBytes(); 199 | } 200 | MessageDigest md = null; 201 | try { 202 | md = MessageDigest.getInstance("SHA"); 203 | } catch (NoSuchAlgorithmException e) { 204 | e.printStackTrace(); 205 | return null; 206 | } 207 | return toHex(md.digest(value)); 208 | 209 | } 210 | 211 | 212 | } -------------------------------------------------------------------------------- /src/cn/tf/utils/SendMailThread.java: -------------------------------------------------------------------------------- 1 | package cn.tf.utils; 2 | 3 | import java.util.Properties; 4 | 5 | import javax.mail.Message; 6 | import javax.mail.MessagingException; 7 | import javax.mail.NoSuchProviderException; 8 | import javax.mail.Session; 9 | import javax.mail.Transport; 10 | import javax.mail.internet.AddressException; 11 | import javax.mail.internet.InternetAddress; 12 | import javax.mail.internet.MimeMessage; 13 | 14 | import cn.tf.domain.Customer; 15 | 16 | public class SendMailThread extends Thread{ 17 | 18 | private Customer customer; 19 | public SendMailThread(Customer customer){ 20 | this.customer=customer; 21 | } 22 | 23 | public void run(){ 24 | 25 | Properties props=new Properties(); 26 | 27 | props.setProperty("mail.transport.protocol", "smtp");//规范规定的参数 28 | props.setProperty("mail.host", "smtp.mxhichina.com");//这里使用万网的邮箱主机 29 | props.setProperty("mail.smtp.auth", "true");//请求认证,不认证有可能发不出去邮件。 30 | 31 | Session session=Session.getInstance(props); 32 | MimeMessage message=new MimeMessage(session); 33 | 34 | try { 35 | message.setFrom(new InternetAddress("xingtian@tianfang1314.cn")); 36 | message.setRecipients(Message.RecipientType.TO, customer.getEmail()); 37 | 38 | message.setSubject("来自指令汇科技书店的注册邮件"); 39 | message.setContent("","text/html;charset=UTF-8"); 40 | 41 | message.setContent("亲爱的"+customer.getUsername()+":
请猛戳下面激活您的账户激活
", "text/html;charset=UTF-8"); 42 | message.saveChanges(); 43 | 44 | Transport ts = session.getTransport(); 45 | ts.connect("你的邮箱账号", "你的密码"); 46 | ts.sendMessage(message, message.getAllRecipients()); 47 | ts.close(); 48 | } catch (AddressException e) { 49 | // TODO Auto-generated catch block 50 | e.printStackTrace(); 51 | } catch (NoSuchProviderException e) { 52 | // TODO Auto-generated catch block 53 | e.printStackTrace(); 54 | } catch (MessagingException e) { 55 | // TODO Auto-generated catch block 56 | e.printStackTrace(); 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/cn/tf/utils/WebUtil.java: -------------------------------------------------------------------------------- 1 | package cn.tf.utils; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | import org.apache.commons.beanutils.BeanUtils; 8 | 9 | import cn.tf.domain.Category; 10 | 11 | public class WebUtil { 12 | 13 | public static T fillBean(HttpServletRequest request,Class clazz){ 14 | try { 15 | T bean=clazz.newInstance(); 16 | BeanUtils.populate(bean, request.getParameterMap()); 17 | return bean; 18 | } catch (Exception e) { 19 | throw new RuntimeException(e); 20 | } 21 | } 22 | 23 | public static Category fillBean(String name, Class class1) { 24 | 25 | return null; 26 | } 27 | 28 | 29 | } 30 | --------------------------------------------------------------------------------