📄 bookinfaction.java
字号:
package com.wang.action.bookinf;
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.bookinf.BookInfActionForm;
import org.apache.struts.action.Action;
import java.util.ArrayList;
import com.wang.bean.*;
import java.sql.*;
import com.wang.db.MyDb;
public class BookInfAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
BookBean bbean = new BookBean();
BookBean oldBean = null;
MyDb md = new MyDb();
BookInfActionForm bookInfActionForm = (BookInfActionForm) form;
java.util.ArrayList list = (ArrayList) request.getSession().
getAttribute("list");
if (list == null)
{
list = new ArrayList();
}
if (request.getParameter("bookId") == null)
{
boolean flag = false;
String bookName = bookInfActionForm.getBookName();
bbean.setBookName(bookName);
String bookId = bookInfActionForm.getBookId();
bbean.setBookId(Integer.parseInt(bookId));
String bookPenster = bookInfActionForm.getBookPenster();
bbean.setBookPenster(bookPenster);
String bookCompany = bookInfActionForm.getBookCompany();
bbean.setBookCompany(bookCompany);
String bookPrice = bookInfActionForm.getBookPrice();
bbean.setBookPrice(Integer.parseInt(bookPrice));
String bookStorage = bookInfActionForm.getBookStorage();
bbean.setBookStorage(Integer.parseInt(bookStorage));
String bookSynopsis = bookInfActionForm.getBookSynopsis();
bbean.setBookSynopsis(bookSynopsis);
bbean.setBookData(new java.util.Date());
bbean.setBookCount(1);
String bookType = bookInfActionForm.getBookType();
bookType = md.queryType(bookType);
md.Close();
bbean.setBookAllPrice(bbean.getBookPrice());
bbean.setBookType(bookType);
for (int i = 0; i < list.toArray().length; i++)
{
oldBean = (com.wang.bean.BookBean) list.get(i);
if (bbean.getBookId() == oldBean.getBookId())
{
//bbean.setBookCount(oldBean.getBookCount() + 1);
((com.wang.bean.BookBean) list.get(i)).setBookCount(oldBean.
getBookCount() + 1);
((BookBean) list.get(i)).setBookAllPrice(oldBean.
getBookAllPrice() + oldBean.getBookPrice());
flag = true;
request.getSession().setAttribute("zongshu",(Integer.parseInt((request.getSession().getAttribute("zongshu")).toString()))+1);
request.getSession().setAttribute("gongji",((BookBean) list.get(i)).getBookPrice()+Integer.parseInt((request.getSession().getAttribute("gongji").toString())));
break; // mapping.findForward("shopcar");
}
}
if (!flag)
{
list.add(bbean);
request.getSession().setAttribute("list", list);
request.getSession().setAttribute("zongshu",(Integer.parseInt((request.getSession().getAttribute("zongshu")).toString()))+1);
request.getSession().setAttribute("shangpin",(Integer.parseInt((request.getSession().getAttribute("shangpin")).toString()))+1);
request.getSession().setAttribute("gongji",bbean.getBookPrice()+Integer.parseInt((request.getSession().getAttribute("gongji").toString())));
}
}
if (request.getParameter("bookId") != null)
{
boolean flag = false;
bbean = md.getBookBean(request.getParameter("bookId"));
for (int i = 0; i < list.toArray().length; i++)
{
oldBean = (com.wang.bean.BookBean) list.get(i);
if (bbean.getBookId() == oldBean.getBookId())
{
((BookBean) list.get(i)).setBookCount(oldBean.getBookCount() +
1);
((BookBean) list.get(i)).setBookAllPrice(oldBean.
getBookAllPrice() + oldBean.getBookPrice());
flag = true;
request.getSession().setAttribute("zongshu",(Integer.parseInt((request.getSession().getAttribute("zongshu")).toString()))+1);
request.getSession().setAttribute("gongji",((BookBean) list.get(i)).getBookPrice()+Integer.parseInt((request.getSession().getAttribute("gongji").toString())));
break; //return mapping.findForward("shopcar");
}
}
if (!flag)
{
list.add(bbean);
request.getSession().setAttribute("list", list);
request.getSession().setAttribute("zongshu",(Integer.parseInt((request.getSession().getAttribute("zongshu")).toString()))+1);
request.getSession().setAttribute("shangpin",(Integer.parseInt((request.getSession().getAttribute("shangpin")).toString()))+1);
request.getSession().setAttribute("gongji",bbean.getBookPrice()+Integer.parseInt((request.getSession().getAttribute("gongji").toString())));
}
}
return mapping.findForward("shopcar");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -