Java项目:基于Jsp实现网上定餐系统

简介: 项目基于JSP+SERVLET+Durid连接池进行开发实现,数据库采用MYSQL数据库,开发工具为IDEA或ECLIPSE,前端用采用BootStrap开发实现。系统采用三层架构设计,MVC设计模式。系统功能完整,页面简洁大方,维护方便,适合做毕业设计使用。具体系统功能展示如下:

 作者主页:编程指南针

简介:Java领域优质创作者、CSDN博客专家  Java项目、简历模板、学习资料、面试题库、技术互助

文末获取源码

项目编号:BS-SC-001

本项目基于JSP+SERVLET+Durid连接池进行开发实现,数据库采用MYSQL数据库,开发工具为IDEA或ECLIPSE,前端用采用BootStrap开发实现。系统采用三层架构设计,MVC设计模式。系统功能完整,页面简洁大方,维护方便,适合做毕业设计使用。

具体系统功能展示如下:

前台页面功能:

image.gif编辑

分类显示

image.gif编辑

餐品详情

image.gif编辑

添加购物车

image.gif编辑

个人订单管理

image.gif编辑

个人资料修改

image.gif编辑

系统留言

image.gif编辑

最近浏览功能

image.gif编辑

后台管理功能:

管理员登陆:  admin / admin

image.gif编辑

用户管理

image.gif编辑

分类管理

image.gif编辑

餐品管理

image.gif编辑

订单管理

image.gif编辑

留言管理

image.gif编辑

新闻管理

image.gif编辑

本系统是一款优秀的毕业设计系统,完美的实现了基于餐饮业务的网上订餐流程,功能强大,运行稳定,结构清晰,便于修改,适合做毕业设计使用。

部分核心代码:

package cn.jbit.easybuy.web;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import cn.jbit.easybuy.biz.FacilityService;
import cn.jbit.easybuy.biz.OrderService;
import cn.jbit.easybuy.biz.ProductService;
import cn.jbit.easybuy.biz.impl.FacilityServiceImpl;
import cn.jbit.easybuy.biz.impl.OrderServiceImpl;
import cn.jbit.easybuy.biz.impl.ProductServiceImpl;
import cn.jbit.easybuy.entity.News;
import cn.jbit.easybuy.entity.Pager;
import cn.jbit.easybuy.entity.Product;
import cn.jbit.easybuy.entity.ProductCategory;
import cn.jbit.easybuy.entity.ShoppingCart;
import cn.jbit.easybuy.entity.User;
import cn.jbit.easybuy.util.ActionResult;
import cn.jbit.easybuy.util.Validator;
public class CartServlet extends HttpServlet {
  protected Map<String, ActionResult> viewMapping = new HashMap<String, ActionResult>();
  private ProductService productService;
  private FacilityService facilityService;
  private OrderService orderService;
  public void init() throws ServletException {
    productService = new ProductServiceImpl();
    facilityService = new FacilityServiceImpl();
    orderService = new OrderServiceImpl();
  }
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    doPost(req, resp);
  }
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    req.setCharacterEncoding("utf-8");
    createViewMapping();
    String actionIndicator = req.getParameter("action");
    String result = "";
    if (actionIndicator == null)
      actionIndicator = "list";
    if ("list".endsWith(actionIndicator)) {
      result = list(req);
    } else if ("add".endsWith(actionIndicator)) {
      result = add(req);
    } else if ("mod".endsWith(actionIndicator)) {
      result = mod(req);
    } else if ("remove".endsWith(actionIndicator)) {
      result = remove(req);
    } else if ("pay".endsWith(actionIndicator)) {
      result = pay(req);
    }
    toView(req, resp, result);
  }
  private String pay(HttpServletRequest request) {
    ShoppingCart cart = getCartFromSession(request);
    User user = getUserFromSession(request);
    if(user==null)
      return "login";
    orderService.payShoppingCart(cart, user);
    removeCartFromSession(request);
    return "paySuccess";
  }
  private void removeCartFromSession(HttpServletRequest request) {
    request.getSession().removeAttribute("cart");
  }
  private User getUserFromSession(HttpServletRequest request) {
    HttpSession session = request.getSession();
    return (User) session.getAttribute("loginUser");
  }
  private String add(HttpServletRequest request) {
    String id = request.getParameter("entityId");
    String quantityStr = request.getParameter("quantity");
    long quantity = 1;
    if (!Validator.isEmpty(quantityStr))
      quantity = Long.parseLong(quantityStr);
    Product product = productService.findById(id);
    ShoppingCart cart = getCartFromSession(request);
    cart.addItem(product, quantity);
    return "addSuccess";
  }
  private String mod(HttpServletRequest request) {
    String id = request.getParameter("entityId");
    String quantityStr = request.getParameter("quantity");
    long quantity = 1;
    if (!Validator.isEmpty(quantityStr))
      quantity = Long.parseLong(quantityStr);
    String indexStr = request.getParameter("index");
    ShoppingCart cart = getCartFromSession(request);
    cart.modifyQuantity(Integer.parseInt(indexStr), quantity);
    return "modSuccess";
  }
  private String remove(HttpServletRequest request) {
    String id = request.getParameter("entityId");
    String quantityStr = request.getParameter("quantity");
    long quantity = 1;
    if (!Validator.isEmpty(quantityStr))
      quantity = Long.parseLong(quantityStr);
    String indexStr = request.getParameter("index");
    ShoppingCart cart = getCartFromSession(request);
    cart.getItems().remove(Integer.parseInt(indexStr));
    return "removeSuccess";
  }
  private ShoppingCart getCartFromSession(HttpServletRequest request) {
    HttpSession session = request.getSession();
    ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");
    if (cart == null) {
      cart = new ShoppingCart();
      session.setAttribute("cart", cart);
    }
    //取出当前用户的订单列表
    return cart;
  }
  private String list(HttpServletRequest request) {
    getCartFromSession(request);
    return "listSuccess";
  }
  private void prepareCategories(HttpServletRequest request) {
    List<ProductCategory> categories = productService
        .getProductCategories(null);
    request.setAttribute("categories", categories);
  }
  private void prepareNews(HttpServletRequest request) {
    List<News> allNews = facilityService.getAllNews(new Pager(10, 1));
    request.setAttribute("allNews", allNews);
  }
  protected void createViewMapping() {
    this.addMapping("listSuccess", "shopping.jsp");
    this.addMapping("paySuccess", "shopping-result.jsp");
    this.addMapping("addSuccess", "Cart", true);
    this.addMapping("removeSuccess", "Cart", true);
    this.addMapping("modSuccess", "Cart", true);
    this.addMapping("login", "login.jsp");
  }
  private void toView(HttpServletRequest req, HttpServletResponse resp,
      String result) throws IOException, ServletException {
    ActionResult dest = this.viewMapping.get(result);
    if (dest.isRedirect()) {
      resp.sendRedirect(dest.getViewName());
    } else {
      req.getRequestDispatcher(dest.getViewName()).forward(req, resp);
    }
  }
  protected void addMapping(String viewName, String url) {
    this.viewMapping.put(viewName, new ActionResult(url));
  }
  protected void addMapping(String viewName, String url, boolean isDirect) {
    this.viewMapping.put(viewName, new ActionResult(url, isDirect));
  }
}

image.gif

package cn.jbit.easybuy.web;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.jbit.easybuy.biz.ProductService;
import cn.jbit.easybuy.biz.impl.ProductServiceImpl;
import cn.jbit.easybuy.entity.ProductCategory;
import cn.jbit.easybuy.util.ActionResult;
import cn.jbit.easybuy.util.Validator;
public class CategoryServlet extends HttpServlet {
  private ProductService productService;
  public void init() throws ServletException {
    productService = new ProductServiceImpl();
  }
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    doPost(req, resp);
  }
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    req.setCharacterEncoding("utf-8");
    String actionIndicator = req.getParameter("action");
    ActionResult result = new ActionResult("error");
    Validator validator = new Validator(Validator.toSingleParameters(req));
    if (actionIndicator == null)
      actionIndicator = "list";
    if ("read".endsWith(actionIndicator)) {
      result = read(req, validator);
    } else if ("list".endsWith(actionIndicator)) {
      result = list(req, validator);
    } else if ("create".endsWith(actionIndicator)) {
      result = create(req, validator);
    } else if ("delete".endsWith(actionIndicator)) {
      result = delete(req, validator);
    } else if ("save".endsWith(actionIndicator)) {
      boolean isEdit = true;
      String editIndicator = req.getParameter("entityId");
      if (Validator.isEmpty(editIndicator))
        isEdit = false;
      result = save(req, validator, isEdit);
    }
    if (!validator.hasErrors() && result.isRedirect()) {
      resp.sendRedirect(result.getViewName());
    } else {
      req.setAttribute("errors", validator.getErrors());
      req.getRequestDispatcher(result.getViewName()).forward(req, resp);
    }
  }
  public ActionResult read(HttpServletRequest request, Validator validator) {
    ProductCategory category = productService.findCategoryById(request
        .getParameter("entityId"));
    pupulateRequest(request, category);
    List<ProductCategory> categories = productService.getRootCategories();
    request.setAttribute("categories", categories);
    return new ActionResult("productClass-modify.jsp");
  }
  public ActionResult save(HttpServletRequest request, Validator validator,
      boolean isEdit) {
    String entityId = request.getParameter("entityId");
    checkInputErrors(request, validator);
    saveToDatabase(request, validator, isEdit);
    return new ActionResult("Category", true);
  }
  public ActionResult create(HttpServletRequest request, Validator validator) {
    List<ProductCategory> categories = productService.getRootCategories();
    request.setAttribute("categories", categories);
    request.setAttribute("parentId", 0);
    return new ActionResult("productClass-modify.jsp");
  }
  public ActionResult delete(HttpServletRequest request, Validator validator) {
    productService.deleteCategory(request.getParameter("entityId"));
    return new ActionResult("Category", true);
  }
  public ActionResult list(HttpServletRequest request, Validator validator) {
    List<ProductCategory> categories = productService
        .getProductCategories(null);
    request.setAttribute("categories", categories);
    return new ActionResult("productClass.jsp");
  }
  private void saveToDatabase(HttpServletRequest request,
      Validator validator, boolean isEdit) {
    if (!validator.hasErrors()) {
      ProductCategory productCategory;
      if (!isEdit) {
        productCategory = new ProductCategory();
        populateEntity(request, productCategory);
        productCategory.setParentId(Long.parseLong(request
            .getParameter("parentId")));
        productService.saveCategory(productCategory);
      } else {
        productCategory = productService.findCategoryById(request
            .getParameter("entityId"));
        Long parentId = Long
            .parseLong(request.getParameter("parentId"));
        populateEntity(request, productCategory);
        if (parentId == 0) {
          if (productCategory.getId().equals(
              productCategory.getParentId())) {
            // 说明是一级分类,父分类不能修改,只能改名字
            productService.updateCategoryName(productCategory);
          } else {
            // 二级分类修改为一级分类了,需要额外更新:
            // Product原先属于该二级分类的,全部更新一级为它,二级为空
            productCategory.setParentId(productCategory.getId());
            productService.updateCategory(productCategory,
                "Level2To1");
          }
        } else {
          if (!parentId.equals(productCategory.getParentId())) {
            // 二级分类修改了父分类,需要额外更新:
            // Product原先属于该二级分类的,全部更新一级为新的父分类
            productCategory.setParentId(parentId);
            productService.updateCategory(productCategory,
                "ModifyParent");
          } else {
            // 二级分类修改了名字
            productService.updateCategoryName(productCategory);
          }
        }
      }
    }
  }
  private void pupulateRequest(HttpServletRequest request,
      ProductCategory productCategory) {
    request
        .setAttribute("entityId", Long
            .toString(productCategory.getId()));
    request.setAttribute("name", productCategory.getName());
    request.setAttribute("parentId", (productCategory.getParentId()
        .equals(productCategory.getId())) ? 0 : productCategory
        .getParentId());
  }
  private void checkInputErrors(HttpServletRequest request,
      Validator validator) {
    validator.checkRequiredError(new String[] { "name" });
  }
  private void populateEntity(HttpServletRequest request,
      ProductCategory productCategory) {
    productCategory.setName(request.getParameter("name"));
  }
}

image.gif

package cn.jbit.easybuy.web;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.jbit.easybuy.biz.FacilityService;
import cn.jbit.easybuy.biz.ProductService;
import cn.jbit.easybuy.biz.impl.FacilityServiceImpl;
import cn.jbit.easybuy.biz.impl.ProductServiceImpl;
import cn.jbit.easybuy.entity.Comment;
import cn.jbit.easybuy.entity.Pager;
import cn.jbit.easybuy.entity.ProductCategory;
import cn.jbit.easybuy.util.ActionResult;
import cn.jbit.easybuy.util.Validator;
public class CommentServlet extends HttpServlet {
  private FacilityService facilityService;
  private ProductService productService;
  public void init() throws ServletException {
    this.facilityService = new FacilityServiceImpl();
    this.productService = new ProductServiceImpl();
  }
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    doPost(req, resp);
  }
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    req.setCharacterEncoding("utf-8");
    String actionIndicator = req.getParameter("action");
    ActionResult result = new ActionResult("error");
    Validator validator = new Validator(Validator.toSingleParameters(req));
    if (actionIndicator == null)
      actionIndicator = "list";
    if ("read".endsWith(actionIndicator)) {
      result = read(req, validator);
    } else if ("list".endsWith(actionIndicator)) {
      result = list(req, validator);
    } else if ("delete".endsWith(actionIndicator)) {
      result = delete(req, validator);
    } else if ("save".endsWith(actionIndicator)) {
      boolean isEdit = true;
      String editIndicator = req.getParameter("entityId");
      if (Validator.isEmpty(editIndicator))
        isEdit = false;
      result = save(req, validator, isEdit);
    }
    if (!validator.hasErrors() && result.isRedirect()) {
      resp.sendRedirect(result.getViewName());
    } else {
      req.setAttribute("errors", validator.getErrors());
      req.getRequestDispatcher(result.getViewName()).forward(req, resp);
    }
  }
  public ActionResult read(HttpServletRequest request, Validator validator) {
    Comment comment = facilityService.findCommentById(request
        .getParameter("entityId"));
    pupulateRequest(request, comment);
    return new ActionResult("guestbook-modify.jsp");
  }
  public ActionResult save(HttpServletRequest request, Validator validator,
      boolean isEdit) {
    checkInputErrors(request, validator);
    saveToDatabase(request, validator, isEdit);
    return new ActionResult("GuestBook", true);
  }
  public ActionResult delete(HttpServletRequest request, Validator validator) {
    facilityService.deleteComment(request.getParameter("entityId"));
    return new ActionResult("GuestBook", true);
  }
  public ActionResult list(HttpServletRequest request, Validator validator) {
    String page = request.getParameter("page");
    int pageNo = 1;
    if (!Validator.isEmpty(page))
      pageNo = Integer.parseInt(page);
    long rowCount = facilityService.getCommentRowCount();
    Pager pager = new Pager(rowCount, pageNo);
    List<Comment> comments = facilityService.getComments(pager);
    List<ProductCategory> categories = productService
        .getProductCategories(null);
    request.setAttribute("categories", categories);
    request.setAttribute("comments", comments);
    request.setAttribute("pager", pager);
    request.setAttribute("pageNo", pageNo);
    return new ActionResult("guestbook.jsp");
  }
  private void pupulateRequest(HttpServletRequest request, Comment comment) {
    request.setAttribute("entityId", Long.toString(comment.getId()));
    request.setAttribute("reply", comment.getReply());
    request.setAttribute("content", comment.getContent());
    request.setAttribute("nickName", comment.getNickName());
    request.setAttribute("replayTime", Validator.dateToString(comment
        .getReplyTime()));
  }
  private void saveToDatabase(HttpServletRequest request,
      Validator validator, boolean isEdit) {
    if (!validator.hasErrors()) {
      Comment comment;
      if (!isEdit) {
        comment = new Comment();
        comment.setCreateTime(new Date());
        populateEntity(request, comment);
        facilityService.saveComment(comment);
      } else {
        comment = facilityService.findCommentById(request
            .getParameter("entityId"));
        if (!Validator.isEmpty(request.getParameter("reply"))) {
          comment.setReply(request.getParameter("reply"));
          comment.setReplyTime(new Date());
        }
        facilityService.updateComment(comment);
      }
    }
  }
  private void checkInputErrors(HttpServletRequest request,
      Validator validator) {
    validator.checkRequiredError(new String[] { "content", "nickName" });
  }
  private void populateEntity(HttpServletRequest request, Comment comment) {
    comment.setContent(request.getParameter("content"));
    comment.setNickName(request.getParameter("nickName"));
  }
}

image.gif


相关文章
|
3天前
|
Java Apache Maven
Java百项管理之新闻管理系统 熟悉java语法——大学生作业 有源码!!!可运行!!!
文章提供了使用Apache POI库在Java中创建和读取Excel文件的详细代码示例,包括写入数据到Excel和从Excel读取数据的方法。
18 6
Java百项管理之新闻管理系统 熟悉java语法——大学生作业 有源码!!!可运行!!!
|
17天前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的服装商城管理系统
基于Java+Springboot+Vue开发的服装商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的服装商城管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
51 2
基于Java+Springboot+Vue开发的服装商城管理系统
|
15天前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的大学竞赛报名管理系统
基于Java+Springboot+Vue开发的大学竞赛报名管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的大学竞赛报名管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
36 3
基于Java+Springboot+Vue开发的大学竞赛报名管理系统
|
16天前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的蛋糕商城管理系统
基于Java+Springboot+Vue开发的蛋糕商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的蛋糕商城管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
45 3
基于Java+Springboot+Vue开发的蛋糕商城管理系统
|
16天前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的美容预约管理系统
基于Java+Springboot+Vue开发的美容预约管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的美容预约管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
29 3
基于Java+Springboot+Vue开发的美容预约管理系统
|
18天前
|
Java 关系型数据库 MySQL
毕设项目&课程设计&毕设项目:springboot+jsp实现的房屋租租赁系统(含教程&源码&数据库数据)
本文介绍了一款基于Spring Boot和JSP技术的房屋租赁系统,旨在通过自动化和信息化手段提升房屋管理效率,优化租户体验。系统采用JDK 1.8、Maven 3.6、MySQL 8.0、JSP、Layui和Spring Boot 2.0等技术栈,实现了高效的房源管理和便捷的租户服务。通过该系统,房东可以轻松管理房源,租户可以快速找到合适的住所,双方都能享受数字化带来的便利。未来,系统将持续优化升级,提供更多完善的服务。
毕设项目&课程设计&毕设项目:springboot+jsp实现的房屋租租赁系统(含教程&源码&数据库数据)
|
17天前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的房产销售管理系统
基于Java+Springboot+Vue开发的房产销售管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的房产销售管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
36 3
基于Java+Springboot+Vue开发的房产销售管理系统
|
18天前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的反诈视频宣传系统
基于Java+Springboot+Vue开发的反诈视频宣传系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的反诈视频宣传管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
47 4
基于Java+Springboot+Vue开发的反诈视频宣传系统
|
18天前
|
前端开发 JavaScript Java
基于Java+Springboot+Vue开发的医院门诊预约挂号系统
基于Java+Springboot+Vue开发的医院门诊预约挂号系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的门诊预约挂号管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。
46 2
基于Java+Springboot+Vue开发的医院门诊预约挂号系统
|
1天前
|
Java 应用服务中间件 Maven
idea+maven+tomcat+spring 创建一个jsp项目
这篇文章介绍了如何在IntelliJ IDEA中使用Maven和Tomcat创建一个JSP项目,包括配置Maven依赖、设置Tomcat服务器、编写JSP页面、创建控制器和配置文件,以及项目的运行结果。
8 0
idea+maven+tomcat+spring 创建一个jsp项目