基于javaweb+jsp的共享租车信息管理系统(java+Jsp+Servlet+Jdbc+Mysql)
基于servlet+jsp+jdbc的后台管理系统,包含5个模块:汽车账户部管理、租车账户部管理、汽车信息管理表、租车记录表、租车租聘表。功能完整,均能实现增删查改。
运行环境:
jdk8+tomcat8.5+mysql5.7+Eclipse
项目技术:
servlet+jsp+jdbc+easyui+jquery
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
</div>
<div class="input">
<span>密码 <label style="color:red;">*</label></span>
<input type="text" name="password" placeholder="请输入密码" required="required">
</div>
<div class="clearfix"> </div>
</div>
<div class="register-but text-center">
<input type="submit" value="提交">
<div class="clearfix"> </div>
</div>
</form>
<div class="clearfix"> </div>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<title>用户登录</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.css">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/simpleCart.min.js"></script>
</head>
<body>
<!--header-->
<jsp:include page="header.jsp">
<jsp:param name="flag" value="9"></jsp:param>
</jsp:include>
<!--//header-->
<!--account-->
<div class="account">
<!--header-->
<jsp:include page="header.jsp">
<jsp:param name="flag" value="9"></jsp:param>
</jsp:include>
<!--//header-->
<!--account-->
<div class="account">
<div class="container">
<div class="register">
*/
public String changeOrderItem(HttpServletRequest request, HttpServletResponse response, Page page) throws UnsupportedEncodingException {
System.out.println("调用了ForeServlet changeOrderItem方法");
User user = (User) request.getSession().getAttribute("user");
if (null == user)
return "%fail";
int pid = Integer.parseInt(request.getParameter("pid"));
int number = Integer.parseInt(request.getParameter("number"));
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if (oi.getProduct().getId() == pid) {
oi.setNumber(number);
orderItemDAO.update(oi);
break;
}
}
return "%success";
}
/**
* 删除订单项
*
* @param request
* @param response
* @param page
* @return
*/
public String checkLogin(HttpServletRequest request, HttpServletResponse response, Page page) {
User user = (User) request.getSession().getAttribute("user");
if (user != null) {
return "%success";
}
return "%fail";
}
/**
* 模态登录框通过 Ajax 方法登录
*
* @param request
* @param response
* @param page
* @return
*/
return "alipay.jsp";
}
/**
* 支付完成界面
* @param request
* @param response
* @param page
* @return
*/
public String payed(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet payed方法");
<jsp:param name="flag" value="9"></jsp:param>
</jsp:include>
<!--//header-->
<!--account-->
<div class="account">
<div class="container">
<div class="register">
<c:if test="${!empty msg }">
<div class="alert alert-success">${msg }</div>
</c:if>
<c:if test="${!empty failMsg }">
out.write("</script>");
out.close();
// request.getRequestDispatcher("").forward(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
}
主页登陆注册业务:
public class ForeServlet extends BaseForeServlet {
/**
* 显示主页
*
* @param request
* @param response
* @param page
* @return
*/
public String home(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了 ForeServlet home方法");
List<Category> cs = new CategoryDAO().list();
System.out.println("调用了ForeServlet category方法");
int cid = Integer.parseInt(request.getParameter("cid"));
// 获取分类对象并为填充产品对象、销量、评价
Category c = new CategoryDAO().get(cid);
new ProductDAO().fill(c);
new ProductDAO().setSaleAndReviewNumber(c.getProducts());
// 根据获取的排序方式进行排序
String sort = request.getParameter("sort");
if (null != sort) {
switch (sort) {
case "review":
Collections.sort(c.getProducts(), new ProductReviewComparator());
break;
case "date":
Collections.sort(c.getProducts(), new ProductDateComparator());
break;
case "saleCount":
Collections.sort(c.getProducts(), new ProductSaleCountComparator());
break;
case "price":
Collections.sort(c.getProducts(), new ProductPriceComparator());
break;
order.setStatus(OrderDAO.waitDelivery);
order.setPayDate(new Date());
orderDAO.update(order);
request.setAttribute("o", order);
return "payed.jsp";
}
/**
* 我的订单页面
* @param request
* @param response
* @param page
* @return
*/
public String bought(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet bought方法");
User user = (User) request.getSession().getAttribute("user");
List<Order> os = orderDAO.list(user.getId(), OrderDAO.delete);
orderItemDAO.fill(os);
request.setAttribute("os", os);
return "bought.jsp";
}
}
用户登陆页面:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
User user = (User) request.getSession().getAttribute("user");
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
int oiid = 0;
boolean found = false;
// 遍历订单,如果订单已存在对应的产品,就在对应购物车的基础上调整数量
if (null != ois) {
for (OrderItem oi : ois) {
if (oi.getProduct().getId() == p.getId()) {
oi.setNumber(oi.getNumber() + num);
orderItemDAO.update(oi);
found = true;
oiid = oi.getId();
break;
}
}
}
// 如果没找到对应的商品,则新建一条订单项
return "category.jsp";
}
/**
* 搜索功能
*
* @param request
* @param response
* @param page
* @return
*/
List<Product> ps = null;
// 加入异常,防止崩溃
try {
ps = productDAO.search(keyword, 0, 50);
} catch (Exception e) {
e.printStackTrace();
}
// 设置产品的销量和评论
productDAO.setSaleAndReviewNumber(ps);
request.setAttribute("ps", ps);
return "searchResult.jsp";
}
/**
* @return
*/
public String category(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet category方法");
int cid = Integer.parseInt(request.getParameter("cid"));
// 获取分类对象并为填充产品对象、销量、评价
Category c = new CategoryDAO().get(cid);
new ProductDAO().fill(c);
new ProductDAO().setSaleAndReviewNumber(c.getProducts());
// 根据获取的排序方式进行排序
String sort = request.getParameter("sort");
if (null != sort) {
Order order = orderDAO.get(oid);
order.setStatus(OrderDAO.waitDelivery);
order.setPayDate(new Date());
orderDAO.update(order);
request.setAttribute("o", order);
return "payed.jsp";
}
/**
* 我的订单页面
* @param request
* @param response
* @param page
* @return
*/
public String bought(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet bought方法");
User user = (User) request.getSession().getAttribute("user");
List<Order> os = orderDAO.list(user.getId(), OrderDAO.delete);
orderItemDAO.fill(os);
request.setAttribute("os", os);
return "bought.jsp";
}
}
request.setAttribute("total", total);
return "buy.jsp";
}
/**
* 购物车
*
* @param request
* @param response
* @param page
* @return
request.setAttribute("total", total);
return "buy.jsp";
}
/**
* 购物车
*
* @param request
* @param response
* @param page
* @return
*/
public String cart(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet cart方法");
User user = (User) request.getSession().getAttribute("user");
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
request.setAttribute("ois", ois);
return "cart.jsp";
}
/**
* 加入购物车
*
* @param page
* @return
*/
public String home(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了 ForeServlet home方法");
List<Category> cs = new CategoryDAO().list();
new ProductDAO().fill(cs);
new ProductDAO().fillByRow(cs);
request.setAttribute("cs", cs);
return "home.jsp";
}
/**
* 注册
*
* @param request
* @param response
* @param page
/**
* 分类页面
*
* @return
*/
public String category(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet category方法");
int cid = Integer.parseInt(request.getParameter("cid"));
// 获取分类对象并为填充产品对象、销量、评价
Category c = new CategoryDAO().get(cid);
new ProductDAO().fill(c);
new ProductDAO().setSaleAndReviewNumber(c.getProducts());
// 根据获取的排序方式进行排序
String sort = request.getParameter("sort");
if (null != sort) {
switch (sort) {
<c:if test="${!empty failMsg }">
<div class="alert alert-danger">${failMsg }</div>
</c:if>
<form action="<%=request.getContextPath()%>/user_login" method="post">
<div class="register-top-grid">
<h3>用户登录</h3>
<div class="input">
<span>用户名/邮箱 <label style="color:red;">*</label></span>
<input type="text" name="ue" placeholder="请输入用户名" required="required">
</div>
<div class="input">
<span>密码 <label style="color:red;">*</label></span>
<input type="text" name="password" placeholder="请输入密码" required="required">
</div>
<div class="clearfix"> </div>
</div>
<div class="register-but text-center">
<input type="submit" value="提交">
// 统计总金额并设置每个订单项的所属订单
float total = 0;
for (OrderItem oi : ois) {
oi.setOrder(order);
orderItemDAO.update(oi);
total += oi.getProduct().getPromotePrice() * oi.getNumber();
}
return "@forealipay?oid=" + order.getId() + "&total=" + total;
}
/**
* 支付界面
*
* @param request
* @param response
* @param page
* @return
*/
public String alipay(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet alipay方法");
return "alipay.jsp";
}
/**
productDAO.setSaleAndReviewNumber(ps);
request.setAttribute("ps", ps);
return "searchResult.jsp";
}
/**
* 立即购买
*
* @param request
* @param response
* @param page
* @return
*/
public String buyone(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet buyone方法");
int pid = Integer.parseInt(request.getParameter("pid"));
int num = Integer.parseInt(request.getParameter("num"));
Product p = productDAO.get(pid);
User user = (User) request.getSession().getAttribute("user");
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
int oiid = 0;
boolean found = false;
// 遍历订单,如果订单已存在对应的产品,就在对应购物车的基础上调整数量
</body>
</html>
添加类型业务:
@WebServlet("/addCategoryServlet")
public class AddCategoryServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String a = request.getParameter("parentId");
String b = request.getParameter("className");
System.out.println("parentId"+a);
System.out.println("className"+b);
Category category = new Category();
category.setCategory_parentid(Integer.valueOf(a));
category.setCategory_name(b);
CategoryService service = new CategoryServiceImpl();
service.addCategory(category);
break;
case "date":
Collections.sort(c.getProducts(), new ProductDateComparator());
break;
case "saleCount":
Collections.sort(c.getProducts(), new ProductSaleCountComparator());
break;
case "price":
Collections.sort(c.getProducts(), new ProductPriceComparator());
break;
case "all":
Collections.sort(c.getProducts(), new ProductAllComparator());
break;
}
}
// 排序完成后,将分类对象添加到域对象 request 中
int number = Integer.parseInt(request.getParameter("number"));
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if (oi.getProduct().getId() == pid) {
oi.setNumber(number);
orderItemDAO.update(oi);
break;
}
}
return "%success";
}
/**
oi.setProduct(p);
oi.setNumber(num);
orderItemDAO.add(oi);
oiid = oi.getId();
}
return "%success";
}
/**
* 更改当前订单项的内容
*
* @param request
* @param response
* @param page
System.out.println("调用了 ForeServlet product方法");
int pid = Integer.parseInt(request.getParameter("pid"));
Product p = productDAO.get(pid);
// 获取产品的single图片和detail图片
List<ProductImage> productSingleImages = productImageDAO.list(p, ProductImageDAO.type_single);
List<ProductImage> productDetailImages = productImageDAO.list(p, ProductImageDAO.type_detail);
p.setProductSingleImages(productSingleImages);
p.setProductDetailImages(productDetailImages);
//p.setFirstProductImage(productSingleImages.get(0));
// 获取产品属性信息
List<PropertyValue> pvs = propertyValueDAO.list(p.getId());
// 获取产品评价信息
List<Review> reviews = reviewDAO.list(p.getId());
// 设置产品销量数和评价数
productDAO.setSaleAndReviewNumber(p);
request.setAttribute("p", p);
request.setAttribute("pvs", pvs);
request.setAttribute("reviews", reviews);
return "product.jsp";
}
/**
* 分类页面