java web 实现基本的购物车功能

  • 源码资源
  • 0
  • 48
  • 0
  • 169
  • 扫一扫,手机访问
  • 免费
  • 7.7折 (原价:¥0 )
  • 开通VIP立省0 点我开通VIP
  • 商品特色:
  • 担保交易
  • 自动发货
  • 商品详情
  • 技术栈
  • 功能脑图
  • 演示介绍
  • 售后服务
  • 版权信息
  • 商品问答
  • 累计评价 0
  • 交易规则
项目要求
 

package packg.cn1;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import packag.cn.User;
/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		response.setContentType("text/html;charset=UTF-8");
		//request.setCharacterEncoding("utf-8");
		//获取页面元素内容
		String userName = request.getParameter("username");
		String password = request.getParameter("password");
		String checkCode = request.getParameter("check_code");
		String savedCode = (String) request.getSession().getAttribute("check_code");
		PrintWriter pw = response.getWriter();
		if (("xyz").equals(userName)  && ("123456").equals(password) && checkCode.equals(savedCode)) {
			User user = new User(); 
			user.setUserNname(userName);
			user.setPassword(password);
			request.getSession().setAttribute("user",user);
			response.sendRedirect("IndexServlet");
		}else if(checkCode.equals(savedCode)){
			pw.write("用户名或密码错误,登录失败");
			response.getWriter().print("您还没有登录,请登录");
		}else {
			pw.write("验证码错误");
		}
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
}





 


package packg.cn1;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dao.BookDB;
import oracle.jrockit.jfr.openmbean.ProducerDescriptorType;
import packag.cn.Cart;
import packag.cn.Book;
import service.BusinessService;
/**
 * Servlet implementation class DeletServlet
 * @param* @param*/
@WebServlet("/DeleteServlet")
public class DeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		//获取得到用户想要删除哪个书本的id
		String id = request.getParameter("bookid");
		//获取该用户相对应的购物车对象
		Cart cart = (Cart) request.getSession().getAttribute("cart");
		try {
		  //删除购物车的商品,也应该是在BusinessService中有的功能,于是乎又回到BusinessService中写代码
		  BusinessService businessService = new BusinessService();
		 // businessService.deleteBook(id, cart);
		  businessService.deleteBook(id, cart);
		  //删除购物车的商品后,也应该直接跳转回去购物车的显示页面中
		  request.getRequestDispatcher("listCart.jsp").forward(request, response);
		} catch (FileNotFoundException e) {
		  request.setAttribute("message", "购物车空了!");
		  request.getRequestDispatcher("/listBook.jsp").forward(request, response);
		} catch (Exception e) {
		  e.printStackTrace();
		  request.setAttribute("message", "删除中出现了异常~待会再试试呗!");
		  request.getRequestDispatcher("listCart.jsp").forward(request, response);
		}
		//调用购物车删除方法
//		if (id == null) {
//			String url = "Servlet";
//			response.sendRedirect(url);
//			return;
//		}
//		//Book book = BookDB.getBook(id);
//		Book book = (Book) BookDB.getAll();
//		HttpSession session = request.getSession();
//		//List cart = (List) session.getSession();
//		@SuppressWarnings({"unchecked","rawtyoes"})
//		//List cart = (List) session.getAttribute("cart");
//		//ArrayListcart = (ArrayList) session.getAttribute("cart");
//		ArrayListcart1 = (ArrayList) session.getAttribute("cart");
//		cart1.remove(book);
//		
//		String url = "CartServlet";
//	//	response.sendRedirect(url);
//		String newurl = response.encodeRedirectUrl(url);
//		response.sendRedirect(newurl);
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
}

 


  • 认证类型:
  • 个人店铺
  • 商家认证:
  • 邮箱已绑定 手机号码已绑定 已通过实名认证
  • 工作时间
  • 周一到周日9:00-18:00
  • 描述
    0.00
  • 发货
    0.00
  • 售后
    0.00
已缴保证金0
签到
购物车
客服
赚钱

入驻猿来入此平台

睡后收入不是梦想

我要赚钱
公众号

扫码关注公众号

每月领专属优惠