CSDN博客

img javaindex

BuyServlet

发表于2008/9/28 7:21:00  127人阅读

 package servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BuyServlet extends HttpServlet {

 public BuyServlet() {
  super();
 }

 public void destroy() {
  super.destroy(); // Just puts "destroy" string in log
  // Put your code here
 }

 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  String book = request.getParameter("book");
  String ope = request.getParameter("ope");  
  HttpSession session = request.getSession();  
  ArrayList gwc = (ArrayList)session.getAttribute("gwc");  
  if(gwc==null){
   gwc = new ArrayList();
   session.setAttribute("gwc", gwc);
  }
  if(ope.equals("add")){
   gwc.add(book);//添加到购物车
  }
  if(ope.equals("delete")){
   gwc.remove(book);//添加到购物车
  }
  response.sendRedirect("/PrjFu7/cart.jsp");
  
 
 }

 public void init() throws ServletException {
  // Put your code here
 }

}

阅读全文
0 0

相关文章推荐

img
取 消
img