forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCart.java
More file actions
55 lines (53 loc) · 2.4 KB
/
Cart.java
File metadata and controls
55 lines (53 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import com.actionForm.StockGoodsForm;
import org.apache.struts.action.Action;
import com.dao.InstorageDAO;
public class Cart extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String action = request.getParameter("action");
System.out.println("Action:" + action);
if (action.equals("add")) { //单击“采购”按钮时执行的操作
return add(mapping, form, request, response);
} else if (action.equals("remove")) {
return remove(mapping, form, request, response);
} else if(action.equals("clear")){
return clear(mapping, form, request, response);
}else {
request.setAttribute("err", "您的操作有误!");
return mapping.findForward("error");
}
}
//添加指定物资信息
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
InstorageDAO instorageDAO = new InstorageDAO();
StockGoodsForm stockGoodsForm = (StockGoodsForm) form;
instorageDAO.cart_add(stockGoodsForm, request);
return mapping.findForward("add");
}
//移去指定物资信息
public ActionForward remove(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
InstorageDAO instorageDAO = new InstorageDAO();
int id=Integer.parseInt(request.getParameter("removeid"));
instorageDAO.cart_remove(id, request);
return mapping.findForward("add");
}
//清空保存物资信息的Session
public ActionForward clear(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
InstorageDAO instorageDAO = new InstorageDAO();
instorageDAO.cart_clear(request);
return mapping.findForward("add");
}
}