📄 shopcaraction.java
字号:
package com.wang.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.wang.actionform.ShopCarActionForm;
import org.apache.struts.action.Action;
import com.wang.bean.*;
public class ShopCarAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
{
ShopCarActionForm shopCarActionForm = (ShopCarActionForm) form;
java.util.ArrayList list = (java.util.ArrayList) request.getSession().getAttribute("list");
if (request.getParameter("action") != null) //执行减少
{
String action = request.getParameter("action");
String bookId = request.getParameter("bookId"); //获得需要减少的书编号
if (action.equals("del")) //删除
{
for (int i = 0; i < list.toArray().length; i++)
{
com.wang.bean.BookBean bbean = (com.wang.bean.BookBean) list.get(i);
if ((bbean.getBookId() + "").equals(bookId))
{
list.remove(i);
request.getSession().setAttribute("zongshu", (Integer.parseInt((request.getSession().getAttribute("zongshu")).toString())) - bbean.getBookCount());
request.getSession().setAttribute("shangpin", (Integer.parseInt((request.getSession().getAttribute("shangpin")).toString())) - 1);
request.getSession().setAttribute("gongji", Integer.parseInt((request.getSession().getAttribute("gongji").toString())) - bbean.getBookAllPrice());
break;
}
}
request.getSession().setAttribute("list", list);
return mapping.findForward("shopcar");
}
if (action.equals("countChenge")&&list!=null)
{
for (int i = 0; i < list.toArray().length; i++)
{
if (((BookBean) list.get(i)).getBookCount() != Integer.parseInt(request.getParameter(((BookBean) list.get(i)).getBookId() + "")))
{
if (((BookBean) list.get(i)).getBookCount() < Integer.parseInt(request.getParameter(((BookBean) list.get(i)).getBookId() + "")))
{
request.getSession().setAttribute("zongshu", (Integer.parseInt((request.getSession().getAttribute("zongshu")).toString())) + Integer.parseInt(request.getParameter(((BookBean) list.get(i)).getBookId() + "")) - ((BookBean) list.get(i)).getBookCount());
request.getSession().setAttribute("gongji", Integer.parseInt((request.getSession().getAttribute("gongji").toString())) + (Integer.parseInt(request.getParameter(((BookBean) list.get(i)).getBookId() + "")) - ((BookBean) list.get(i)).getBookCount()) * ((BookBean) list.get(i)).getBookPrice());
}
else
{
request.getSession().setAttribute("zongshu", (Integer.parseInt((request.getSession().getAttribute("zongshu")).toString())) - ((BookBean) list.get(i)).getBookCount() + Integer.parseInt(request.getParameter(((BookBean) list.get(i)).getBookId() + "")));
request.getSession().setAttribute("gongji", Integer.parseInt((request.getSession().getAttribute("gongji").toString())) - (((BookBean) list.get(i)).getBookCount() - Integer.parseInt(request.getParameter(((BookBean) list.get(i)).getBookId() + ""))) * ((BookBean) list.get(i)).getBookPrice());
}
((BookBean) list.get(i)).setBookCount(Integer.parseInt(request.getParameter(((BookBean) list.get(i)).getBookId() + "")));
((BookBean) list.get(i)).setBookAllPrice(((BookBean) list.get(i)).getBookPrice() * Integer.parseInt(request.getParameter(((BookBean) list.get(i)).getBookId() + "")));
}
}
}
if (action.equals("delall"))
{
list = null;
request.getSession().setAttribute("shangpin", "0");
request.getSession().setAttribute("zongshu", "0");
request.getSession().setAttribute("gongji", "0");
}
}
request.getSession().setAttribute("list", list);
return mapping.findForward("shopcar");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -