91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java實現圖片展覽館管理系統的代碼

發布時間:2022-01-27 09:11:23 來源:億速云 閱讀:120 作者:iii 欄目:開發技術

今天小編給大家分享一下Java實現圖片展覽館管理系統的代碼的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

一、項目運行

環境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

項目技術:

Springboot+ SpringMVC + JPA+ Jsp + Html+ JavaScript + JQuery + Ajax + maven等等

Java實現圖片展覽館管理系統的代碼

Java實現圖片展覽館管理系統的代碼

Java實現圖片展覽館管理系統的代碼

Java實現圖片展覽館管理系統的代碼

Java實現圖片展覽館管理系統的代碼

Java實現圖片展覽館管理系統的代碼

訂單服務:

@WebServlet("/order/OrderServlet")
public class OrderServlet extends HttpServlet {
	private OrderService service = new OrderServiceImpl();
	private ClientServiceImpl clientService=new ClientServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		String op = req.getParameter("op");// 得到傳過來的請求
		// 生成訂單
		if (op.equals("genOrder")) {
			genOrder(req, resp);
		}
		// 查看訂單
		if (op.equals("findAllOrders")) {
			findAllOrders(req, resp);
		}
		// 管理員查看訂單
		if (op.equals("findOrders")) {
			findOrders(req, resp);
		}
		// 發貨
		if (op.equals("faHuo")) {
			faHuo(req, resp);
		}
		//刪除訂單
		if(op.equals("deletes")) {
			deletes(req,resp);
		}
	}
 
	private void deletes(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String orderNumber = req.getParameter("orderNum");
		Order findOrderByNum = service.findOrderByNum(orderNumber);
		if(findOrderByNum.getItems().size()!=0) {
			resp.getWriter().print("<script>alert('該訂單下有訂單子項不可刪除,請先刪除訂單子項!')</script>");
			resp.getWriter().print("<script>location.href='../admin/managerOrder.jsp'</script>");
			return;
		}
		try {
			service.deleteByNumber(orderNumber);
			resp.getWriter().print("<script>alert('刪除成功!')</script>");
			resp.sendRedirect("../admin/managerOrder.jsp");
		}catch (Exception e) {
			resp.getWriter().print("<script>alert('該訂單下有訂單子項不可刪除,請先刪除訂單子項!')</script>");
			return;
		}
	}
	
	private void faHuo(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String ordernum = req.getParameter("ordernum");
		service.faHuo(ordernum);
		List<Order> orders = service.findOrders();
		HttpSession session = req.getSession();
		session.setAttribute("orders", orders);
		System.out.println(orders);
		resp.sendRedirect(req.getContextPath() + "/admin/managerOrder.jsp");
	}
 
	private void findOrders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		List<Order> orders = service.findOrders();
		HttpSession session = req.getSession();
		session.setAttribute("orders", orders);
		req.getRequestDispatcher("/admin/managerOrder.jsp").forward(req, resp);
	}
 
	private void findAllOrders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session = req.getSession();
		User user = (User) session.getAttribute("user");
		List<Order> orders = service.findUserOrders(user);
		req.setAttribute("orders", orders);
		req.getRequestDispatcher("/person/personOrder.jsp").forward(req, resp);
	}
 
	private void genOrder(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
		// 取出購物車信息
		// 取出購物項信息
		HttpSession session = req.getSession();
		Cart cart = (Cart) session.getAttribute("cart");
		User user = (User) session.getAttribute("user");
		if (cart == null) {
			session.setAttribute("message", "會話已經結束!");
			req.getRequestDispatcher("../message.jsp").forward(req, resp);
			return;
		}
		//先判斷庫存夠不夠!
		Book book = cart.getBook();
		String book_id = book.getBook_id();
		Book findBookById = clientService.findBookById(book_id);
		if(findBookById.getBook_kunumber()-cart.getTotalQuantity()<0) {
			session.setAttribute("message", "庫存不足,無法購買!");
			session.removeAttribute("cart");
			req.getRequestDispatcher("../message.jsp").forward(req, resp);
			return;
		}
		Order order = new Order();
		order.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		String ordernum = genOrdernum();
		order.setOrdernum(ordernum);
		order.setQuantity(cart.getTotalQuantity());
		order.setMoney(cart.getTotalMoney());
		order.setUser(user);
		// 訂單項
		List<Orderitem> oItems = new ArrayList<Orderitem>();
		for (Map.Entry<String, CartItem> me : cart.getItmes().entrySet()) {
			CartItem cItem = me.getValue();
			Orderitem oItem = new Orderitem();
			oItem.setId(genOrdernum());
			oItem.setBook(cItem.getBook());
			oItem.setPrice(cItem.getMoney());
			oItem.setQuantity(cItem.getQuantity());
			oItem.setOrdernum(ordernum);
			oItems.add(oItem);
		}
		// 建立訂單項和訂單的關系
		order.setItems(oItems);
		service.genOrder(order);
		req.setAttribute("order", order);
		req.getSession().removeAttribute("cart");
		req.removeAttribute("cart");
		req.getRequestDispatcher("/order.jsp").forward(req, resp);
	}
 
	// 生成訂單號
	private String genOrdernum() {
		Date now = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMMdd");
		String s1 = df.format(now);
		return s1 + System.nanoTime();
	}
 
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}

管理員登錄服務:

@WebServlet("/admin/ManagerServlet")
public class ManagerServlet extends HttpServlet {
    private ManagerService service = new ManagerServiceImpl();
 
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        String op = req.getParameter("op");// 得到傳過來的請求
        // 管理員登陸
        if (op.equals("login")) {
            login(req, resp);
        }
        // 修改管理員資料
        if (op.equals("managerInformation")) {
            managerInformation(req, resp);
        }
        // 修改管理員登錄密碼
        if (op.equals("managerPassword")) {
            managerPassword(req, resp);
        }
        // 注銷
        if (op.equals("layout")) {
            layout(req, resp);
        }
        // 添加書籍前先獲取所有分類
        if (op.equals("addBookUI")) {
            addBookUI(req, resp);
        }
        // 添加書籍
        if (op.equals("addBook")) {
            try {
                addBook(req, resp);
            } catch (FileUploadException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        // 添加書籍分類
        if (op.equals("addCategory")) {
            addCategory(req, resp);
        }
        // 文學藝術類書籍列表
        if (op.equals("category")) {
            getCategoryBook(req, resp);
        }
        // 編輯書籍信息前獲取書籍的信息回顯
        if (op.equals("editBookUI")) {
            editBookUI(req, resp);
        }
        // 編輯書籍
        if (op.equals("editBook")) {
            try {
                editBook(req, resp);
            } catch (FileUploadException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        // 刪除書籍
        if (op.equals("delBook")) {
            delBook(req, resp);
        }
        // 獲取書籍分類列表
        if (op.equals("categoryList")) {
            categoryList(req, resp);
        }
        // 獲得分類信息
        if (op.equals("editCategoryUI")) {
            editCategoryUI(req, resp);
        }
        // 修改書籍分類信息
        if (op.equals("editCategory")) {
            editCategory(req, resp);
        }
        // 刪除書籍分類
        if (op.equals("delCategory")) {
            delCategory(req, resp);
        }
        // 用戶信息管理
        if (op.equals("findUsers")) {
            findUsers(req, resp);
        }
        // 添加工作人員
        if (op.equals("addAdmin")) {
            addAdmin(req, resp);
        }
        // 書籍銷售情況
        if (op.equals("sales")) {
            sales(req, resp);
        }
        //搜索
        if(op.equals("search")) {
        	search(req,resp);
        }
    }
    
    private void search(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	  String name = req.getParameter("search");
    	  if(name==null) {
    		  name="";
    	  }
    	  List<Book> findListByBookName = service.findListByBookName(name);
          List<Category> categoryList = service.findAllCategory();// 分類
          req.setAttribute("currentName", name);
          req.setAttribute("books", findListByBookName);
          req.setAttribute("categoryList", categoryList);
          req.getRequestDispatcher("/admin/booksList.jsp").forward(req, resp);
    }
    
    private void sales(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Book> sales = service.sales();
        req.setAttribute("sales", sales);
        req.getRequestDispatcher("/admin/sales.jsp").forward(req, resp);
    }
 
    private void addAdmin(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String name = req.getParameter("name");
        String sex = req.getParameter("sex");
        String tel = req.getParameter("tel");
        Administrator admin = new Administrator(username, password, name, sex, tel);
        service.addAdmin(admin);
        resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                + "/img/duigou.png'/>添加成功!</div>");
    }
 
    private void findUsers(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<User> list = service.findUsers();
        HttpSession session = req.getSession();
        session.setAttribute("users", list);
        req.getRequestDispatcher("/admin/managerUsers.jsp").forward(req, resp);
    }
 
    private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if(username==null || username=="") {
        	  req.setAttribute("message", "請填寫用戶名");
        	  req.getRequestDispatcher("/admin/404.jsp").forward(req, resp);
        	  return;
        }
        if(password==null || password=="") {
        	 req.setAttribute("message", "請填寫密碼");
       	  req.getRequestDispatcher("/admin/404.jsp").forward(req, resp);
       	  return;
        }
        HttpSession session = req.getSession();
        Administrator admin = service.login(username, password);
        if (admin.getUsername() != null && admin.getUsername() != "") {
            req.setAttribute("message", "登陸成功");
            session.setAttribute("admin", admin);
            req.getRequestDispatcher("/admin/message.jsp").forward(req, resp);
        } else {
        	  req.setAttribute("message", "賬號或密碼錯誤!");
        	  req.getRequestDispatcher("/admin/404.jsp").forward(req, resp);
        }
    }
 
    private void managerInformation(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String username = req.getParameter("username");
        String name = req.getParameter("name");
        String sex = req.getParameter("sex");
        String tel = req.getParameter("tel");
        service.managerInformation(username, name, sex, tel);
        HttpSession session = req.getSession();
        Administrator admin = (Administrator) session.getAttribute("admin");
        admin.setName(name);
        admin.setSex(sex);
        admin.setTel(tel);
        session.setAttribute("admin", admin);
        resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                + "/img/duigou.png'/>修改成功!</div>");
 
    }
    //修改管理員密碼
    private void managerPassword(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String repassword = req.getParameter("repassword");
        String oldPassword = req.getParameter("oldPassword");
        if(!password.equals(repassword)) {
        	resp.getWriter().print("<script>alert('兩次密碼不一致')</script>");
        	return;
        }
        Administrator admin = service.findAdminByUsername(username);
        if(!admin.getPassword().equals(oldPassword)) {
        	resp.getWriter().print("<script>alert('舊密碼填寫錯誤!')</script>");
        	return;
        }
        service.managerPassword(username, password);
        resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                + "/img/duigou.png'/>修改成功!</div>");
    }
 
    private void layout(HttpServletRequest req, HttpServletResponse resp) {
        try {
            HttpSession session = req.getSession();
            session.removeAttribute("admin");
            resp.sendRedirect("../admin/managerLogin.jsp");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private void addBookUI(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Category> categorys = service.findAllCategory();
        req.setAttribute("cs", categorys);
        req.getRequestDispatcher("/admin/addBook.jsp").forward(req, resp);
 
    }
 
    private void addBook(HttpServletRequest req, HttpServletResponse resp) throws FileUploadException, IOException {
        // 判斷表單是不是multipart/form-data類型
        boolean isMultipart = ServletFileUpload.isMultipartContent(req);
        if (!isMultipart) {
            throw new RuntimeException("表單上傳類型有誤!!");
        }
        // 創建工廠用來 解析請求內容
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // 構建核心類對象
        ServletFileUpload sfu = new ServletFileUpload(factory);
        List<FileItem> items = new ArrayList<FileItem>();
        items = sfu.parseRequest(req);
        Book book = new Book();
        for (FileItem item : items) {
            if (item.isFormField()) {
                // 普通字段:把數據分裝到book對象中
                processFormField(item, req, book);
            } else {
                // 上傳字段:上傳
                processUplodFiled(item, req, book);
            }
        }
        // 把書籍信息保存到數據庫中
        service.addBook(book);
        resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                + "/img/duigou.png'/>添加成功!</div>");
    }
 
    // 處理文件上傳
    private void processUplodFiled(FileItem item, HttpServletRequest req, Book book) {
        try {
            // 存放路徑:不要放在web-inf中
            // 01.獲取存放文件的真實目錄
          //  String dirImages = getServletContext().getRealPath("/images");
            String dirImages =req.getServletContext().getRealPath("/")+"images/";
//            String dirImages = getServletContext().getRealPath("/img");
            // 02. 通過io存文件
            // 03. 生成文件名 (用戶上傳圖片, 圖片名可能重復)
            String FieldName = item.getFieldName();// 輸入框的name值
            String name = item.getName();
            String fileType = name.substring(name.lastIndexOf(".") + 1);
            String fileName = UUID.randomUUID().toString();// 生成用不重復的文件名
            // 生成文件夾名
			Date time = new Date();
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
			String strTime = simpleDateFormat.format(time);
            // path屬性filename
            String path = strTime +File.separator + "books";// 存放到book對象中的路徑
//            String path = "books";// 存放到book對象中
            String filename = fileName + "." + fileType;
            // fileDir:圖片最終存在于fileDir
            File fileDir = new File(dirImages, path + File.separator + filename);
            // InputStream inputStream = item.getInputStream(); 從請求 對象中 通過流的方式
            // 把 上傳的文件加載到 內存中 構建輸出流
            File parentDir = new File(dirImages, path);// 父目錄
            if (!parentDir.exists()) {
                parentDir.mkdirs();
            }
            book.setFilename(filename);
            book.setPath(path);
 
            InputStream inputStream = item.getInputStream();
            FileOutputStream fos = new FileOutputStream(fileDir);
            int len = 0;
            while ((len = inputStream.read()) != -1) {
                fos.write(len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
 
    }
 
    // 把Fielditem中的數據封裝到book中
    private void processFormField(FileItem item, HttpServletRequest req, Book book) {
        try {
            // item每一個item對象代表一個輸入框
            // 01. 獲取input輸入框的 name 的值 根據規范 輸入框 的name的取值, 與 javabean 中的 屬性名一致
            String inputName = item.getFieldName();
            String inputValue = item.getString("UTF-8");
            if (inputName.equals("categoryid")) {// 分類單獨處理
                // 獲取到選擇的分類的id,根據這個id取到分類的信息
                String categoryid = item.getString();
                System.out.println("categoryid=" + categoryid);
                Category category = service.findCategoryById(categoryid);
                System.out.println(category);
                book.setCategory(category);
            } else {
                BeanUtils.setProperty(book, inputName, inputValue);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    // 添加書籍分類
    private void addCategory(HttpServletRequest req, HttpServletResponse resp) {
        try {
            Category category = new Category();
            BeanUtils.populate(category, req.getParameterMap());
            String categoryName = category.getCategory_name();
            if(StringUtils.isNullOrEmpty(categoryName)) {
            	resp.getWriter().print("<script>alert('請填寫分類名稱')</script>");
            	resp.getWriter().print("<script>location.href='../admin/addCategory.jsp'</script>");
            	return;
            }
            service.addCategory(category);// 調用添加方法
            resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                    + "/img/duigou.png'/>添加成功!</div>");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private void getCategoryBook(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Book> books = service.getCategoryBook(req.getParameter("cid"));// 文學藝術類書籍
        List<Category> categoryList = service.findAllCategory();// 分類
        req.setAttribute("books", books);
        req.setAttribute("categoryList", categoryList);
        req.setAttribute("currentName", "");
        req.getRequestDispatcher("/admin/booksList.jsp").forward(req, resp);
    }
 
    private void editBookUI(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String book_id = req.getParameter("book_id");
        Book book = findBookById(book_id);
        List<Category> category = service.findAllCategory();
        HashMap map = new HashMap();
        map.put("book", book);
        map.put("category", category);
        req.setAttribute("map", map);
        req.getRequestDispatcher("/admin/editBook.jsp").forward(req, resp);
    }
 
    private void editBook(HttpServletRequest req, HttpServletResponse resp) throws FileUploadException, IOException {
        String book_id = req.getParameter("book_id");
        String book_name = req.getParameter("book_name");
        String book_author = req.getParameter("book_author");
        String book_press = req.getParameter("book_press");
        String book_desc = req.getParameter("book_desc");
        double book_price = Double.parseDouble(req.getParameter("book_price"));
        String book_kunumber = req.getParameter("book_kunumber");
        String categoryId = req.getParameter("categoryid");
        Category findCategoryById = service.findCategoryById(categoryId);
        service.editBook(book_id, book_name, book_author, book_press, book_desc, book_price, book_kunumber,findCategoryById);
        resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                + "/img/duigou.png'/>修改成功!</div>");
    }
 
    private void delBook(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String book_id = req.getParameter("book_id");
        service.delBook(book_id);
        resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                + "/img/duigou.png'/>刪除成功!</div>");
    }
 
    private void categoryList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Category> categoryList = service.findAllCategory();
        req.setAttribute("categoryList", categoryList);
        req.getRequestDispatcher("/admin/categorysList.jsp").forward(req, resp);
    }
 
    private void editCategoryUI(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Category category = service.findCategoryById(req.getParameter("category_id"));
        req.setAttribute("category", category);
        req.getRequestDispatcher("/admin/editCategory.jsp").forward(req, resp);
    }
 
    private void editCategory(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Category category = new Category(req.getParameter("category_id"), req.getParameter("category_name"),
                req.getParameter("category_desc"));
        String categoryName = category.getCategory_name();
        if(StringUtils.isNullOrEmpty(categoryName)) {
        	resp.getWriter().print("<script>alert('請填寫分類名稱')</script>");
        	resp.getWriter().print("<script>location.href='../admin/editCategory.jsp'</script>");
        	return;
        }
        service.editCategory(category);
        resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                + "/img/duigou.png'/>修改成功!</div>");
    }
 
    private void delCategory(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String category_id = req.getParameter("category_id");
        service.delCategory(category_id);
        resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
                + "/img/duigou.png'/>刪除成功!</div>");
    }
 
    // 通過書籍id找到書籍信息
    private Book findBookById(String book_id) {
        return service.findBookById(book_id);
    }
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

收藏夾業務處理:

@WebServlet("/client/ClientServlet")
public class ClientServlet extends HttpServlet {
	private ClientService service = new ClientServiceImpl();
	private ManagerService managerService = new ManagerServiceImpl();
 
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		String op = req.getParameter("op");// 得到傳過來的請求
		if (op != null && !op.equals("")) {
			// 登錄
			if (op.equals("login")) {
				login(req, resp);
			}
			// 注銷
			if (op.equals("layout")) {
				layout(req, resp);
			}
			// 注冊
			if (op.equals("register")) {
				register(req, resp);
			}
			// 文學藝術類書籍列表
			if (op.equals("category")) {
				getCategoryBook(req, resp);
			}
 
			// 個人信息修改
			if (op.equals("personInformation")) {
				personInformation(req, resp);
			}
			// 修改密碼
			if (op.equals("personPassword")) {
				personPassword(req, resp);
			}
			// 搜索框
			if (op.equals("search")) {
				search(req, resp);
			}
			// 詳情頁面
			if (op.equals("particulars")) {
				particulars(req, resp);
			}
			// 添加購物車
			if (op.equals("addCart")) {
				addCart(req, resp);
			}
			// 刪除購物車中的購物項
			if (op.equals("delItem")) {
				delItem(req, resp);
			}
			// 修改購物項數量
			if (op.equals("changeNum")) {
				changeNum(req, resp);
			}
			// 添加收藏夾
			if (op.equals("addfavorite")) {
				addfavorite(req, resp);
			}
			// 顯示收藏夾
			if (op.equals("showfavorite")) {
				showfavorite(req, resp);
			}
			// 刪除收藏夾
			if (op.equals("delFavorite")) {
				delFavorite(req, resp);
			}
			// 刪除收藏夾
			if (op.equals("buyNow")) {
				buNow(req, resp);
			}
 
		}
	}
 
	private void delFavorite(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
		String book_id = req.getParameter("book_id");
		service.delFavorite(book_id);
		HttpSession session = req.getSession();
		List<Favorite> lists = (List<Favorite>) session.getAttribute("favorite");
		Iterator<Favorite> iterator = lists.iterator();
		while (iterator.hasNext()) {
			Favorite favorite = iterator.next();
			if (book_id.equals(favorite.getBook().getBook_id())) {
				iterator.remove();// 使用迭代器的刪除方法刪除
			}
		}
		resp.sendRedirect(req.getContextPath() + "/favorite.jsp");
	}
 
	private void showfavorite(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session = req.getSession();
		User user = (User) session.getAttribute("user");
		List<Favorite> favorites = service.findFavoriteByUserId(user);
		session.setAttribute("favorite", favorites);
		req.getRequestDispatcher("/favorite.jsp").forward(req, resp);
	}
 
	private void addfavorite(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		HttpSession session = req.getSession();
		User user = (User) session.getAttribute("user");
		String user_id = user.getId();
		String book_id = req.getParameter("book_id");
		boolean isExit = service.findFavorite(user_id, book_id);
		if (isExit == false) {
			service.addfavorite(user_id, book_id);
		}
	}
 
	private void changeNum(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String num = req.getParameter("num");
		String book_id = req.getParameter("book_id");
		// 取出購物車
		Cart cart = (Cart) req.getSession().getAttribute("cart");
		CartItem item = cart.getItmes().get(book_id);
		item.setQuantity(Integer.parseInt(num));
		resp.sendRedirect(req.getContextPath() + "/showCart.jsp");
 
	}
 
	private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		HttpSession session = req.getSession();
		User user = service.login(username, password);
		if (user.getUsername() != null && user.getUsername() != "") {
			req.setAttribute("message", "登陸成功");
			session.setAttribute("user", user);
			req.getRequestDispatcher("/message.jsp").forward(req, resp);
		} else {
			req.setAttribute("message", "用戶名或密碼錯誤,請重新登錄");
			req.getRequestDispatcher("/message.jsp").forward(req, resp);
		}
	}
 
	private void layout(HttpServletRequest req, HttpServletResponse resp) {
		try {
			HttpSession session = req.getSession();
			session.removeAttribute("user");// 獲取session對象,從session中移除登陸信息
			resp.sendRedirect("../client/ClientServlet?op=category");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
	private void register(HttpServletRequest req, HttpServletResponse resp) {
		try {
			String username = req.getParameter("username");
			String password = req.getParameter("password");
			String name = req.getParameter("name");
			String sex = req.getParameter("sex");
			String tel = req.getParameter("tel");
			String address = req.getParameter("address");
			boolean isExist = false;// 判斷是否存在該用戶
			if (!username.equals("") && !password.equals("")) {
				isExist = service.register(username, password, name, sex, tel, address);
				if (isExist == true) {
					resp.getWriter().print("<script>alert('該用戶已經注冊,請直接登錄')</script>");
					resp.getWriter().print("<script>location.href='../client/ClientServlet?op=category'</script>");
				} else {
					resp.getWriter().write("注冊成功!");
					resp.getWriter().print("<script>location.href='../client/ClientServlet?op=category'</script>");
				}
			}else {
				resp.getWriter().print("<script>alert('請填寫賬號或密碼')</script>");
				resp.getWriter().print("<script>location.href='../client/ClientServlet?op=category'</script>");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
	private void getCategoryBook(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		List<Book> books = service.getCategoryBook(req.getParameter("cid"));// 文學藝術類書籍
		req.setAttribute("books", books);
		List<Category> categoryList= managerService.findAllCategory();
		req.setAttribute("categoryList", categoryList);
		req.getRequestDispatcher("/showBook.jsp").forward(req, resp);
	}
 
	private void personInformation(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String username = req.getParameter("username");
		String name = req.getParameter("name");
		String sex = req.getParameter("sex");
		String tel = req.getParameter("tel");
		String address = req.getParameter("address");
		service.personInformation(username, name, sex, tel, address);
		User user = (User) req.getSession().getAttribute("user");
		user.setUsername(username);
		user.setName(name);
		user.setSex(sex);
		user.setTel(tel);
		user.setAddress(address);
		req.getSession().setAttribute("user", user);
		resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
				+ "/img/duigou.png'/>修改成功!</div>");
	}
 
	private void personPassword(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		String repassword = req.getParameter("repassword");
		String oldPassword = req.getParameter("oldPassword");
		if(!repassword.equals(password)) {
			resp.getWriter().print("<script>alert('兩次密碼不一致')</script>");	
		}
		User user = service.findUserByUserName(username);
		if(user==null) {
			resp.getWriter().print("<script>alert('會話失效或未登錄,請重新登錄!')</script>");	
			return;
		}
		if(!user.getPassword().equals(oldPassword)) {
			resp.getWriter().print("<script>alert('舊密碼輸入錯誤!')</script>");
			return;
		}
		service.personPassword(password, username);
		resp.getWriter().write("<div style='text-align: center;margin-top: 260px'><img src='" + req.getContextPath()
				+ "/img/duigou.png'/>修改成功!</div>");
	}
 
	private void search(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String search = req.getParameter("search");
		List<Book> searchmessage = service.search(search);
		req.setAttribute("books", searchmessage);
		req.setAttribute("name", search==null?"":search);
		req.getRequestDispatcher("/showBook.jsp").forward(req, resp);
	}
 
	private void particulars(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String book_id = req.getParameter("book_id");
		Book book = findBookById(book_id);
		req.setAttribute("book", book);
		req.getRequestDispatcher("/particulars.jsp").forward(req, resp);
	}
 
	// 通過書籍id找到書籍信息
	private Book findBookById(String book_id) {
		Book book = service.findBookById(book_id);
		return book;
	}
 
	private void addCart(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
		String book_id = req.getParameter("book_id");
		Book book = findBookById(book_id);
		HttpSession session = req.getSession();
		Cart cart = (Cart) session.getAttribute("cart");
		if (cart == null) {
			cart = new Cart();
			cart.addBook(book);
			cart.setBook(book);
			session.setAttribute("cart", cart);
		}else {
			session.setAttribute("message", "購物車里有商品,請支付之后再來添加!");
			req.getRequestDispatcher("../message.jsp").forward(req, resp);
			return;
		}
		req.getRequestDispatcher("../showCart.jsp").forward(req, resp);
	}
 
	private void delItem(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String book_id = req.getParameter("book_id");
		Cart cart = (Cart) req.getSession().getAttribute("cart");
		cart.getItmes().remove(book_id);
		req.getSession().removeAttribute("cart");
		resp.sendRedirect(req.getContextPath() + "/showCart.jsp");
	}
 
	private void buNow(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
		Cart cart1 = (Cart) req.getSession().getAttribute("cart");
		if(cart1==null) {
			Cart cart = new Cart();
			String book_id = req.getParameter("book_id");
			Book book = findBookById(book_id);
			cart.addBook(book);
			cart.setBook(book);
			req.getSession().setAttribute("cart", cart);
		}else {
			req.getSession().setAttribute("message", "購物車里有商品,請支付之后再來添加!");
			req.getRequestDispatcher("../message.jsp").forward(req, resp);
			return;
		}
		req.getRequestDispatcher("../showCart.jsp").forward(req, resp);
	}
 
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}

以上就是“Java實現圖片展覽館管理系統的代碼”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

合水县| 金华市| 白银市| 崇州市| 周口市| 江阴市| 澄迈县| 正蓝旗| 宜良县| 维西| 许昌市| 普格县| 乃东县| 潞城市| 大丰市| 梓潼县| 榆中县| 和田县| 霸州市| 泰顺县| 东阳市| 包头市| 土默特右旗| 于田县| 英吉沙县| 洱源县| 枣庄市| 浑源县| 潼关县| 黄山市| 高台县| 滨州市| 丰原市| 东阳市| 宣威市| 镇赉县| 大冶市| 曲松县| 山丹县| 吴桥县| 托克托县|