📄 addcompareaction.java
字号:
package Common;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import Common.DBConnectBean;
public class addCompareAction extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
ServletContext application=getServletConfig().getServletContext();
request.setCharacterEncoding("gb2312");
HttpSession session=request.getSession();
ArrayList compareList=new ArrayList();
ArrayList compareListCopy=new ArrayList();
Hashtable commodity=new Hashtable();
String[] commodityID=request.getParameterValues("id");
if (commodityID==null) System.out.print(" wakao zmshehihih");
if(commodityID!=null){
DBConnectBean dbBean=new DBConnectBean("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:shopping","","");
if(session.getAttribute("compareList".toUpperCase())!=null){
//获取现在客户的购物车里的所有商品的信息及数量
compareList=compareListCopy=(ArrayList)session.getAttribute("compareList".toUpperCase());
}
for (int i=0;i<commodityID.length;i++){
int j=0;
System.out.println("the client now has buy ");
//如果客户已经买了该商品,则添加商品数量
if(compareListCopy!=null){
// System.out.println("不空不空");
for(;j<compareListCopy.size();j++){
Hashtable tb=(Hashtable)compareListCopy.get(j);
String id=tb.get("id".toUpperCase()).toString();
// System.out.print("------finding "+id+commodityID[i]);
if(id.equals(commodityID[i])){
System.out.println("found ");
commodity=tb;
compareList.remove(j);
int commodityNum=Integer.parseInt(tb.get("commodityNum".toUpperCase()).toString())+1;
commodity.put("commodityNum".toUpperCase(),commodityNum);
compareList.add(j,commodity);
// System.out.println("find one has bought");
break;
}
}
}else {
System.out.println("这里是空的");
}
//如果可户还未买该商品,则添加新商品
if(compareListCopy==null||j==compareListCopy.size()){
Hashtable tmptable=new Hashtable();
System.out.println("put this commodity "+commodityID[i]);
tmptable=dbBean.getOneRecord("select * from commodity where id="+commodityID[i]);
commodity=new Hashtable();
commodity.put("id".toUpperCase(),commodityID[i]);
commodity.put("card".toUpperCase(),tmptable.get("card".toUpperCase()));
commodity.put("num".toUpperCase(),tmptable.get("num".toUpperCase()));
commodity.put("model".toUpperCase(),tmptable.get("model".toUpperCase()));
commodity.put("photo".toUpperCase(),tmptable.get("photo".toUpperCase()));
commodity.put("special".toUpperCase(),tmptable.get("special".toUpperCase()));
commodity.put("net".toUpperCase(),tmptable.get("net".toUpperCase()));
commodity.put("describe".toUpperCase(),tmptable.get("describe".toUpperCase()));
commodity.put("price".toUpperCase(),tmptable.get("price".toUpperCase()));
commodity.put("picture".toUpperCase(),tmptable.get("picture".toUpperCase()));
commodity.put("commodityNum".toUpperCase(),1);
compareList.add(commodity);
}
}
// System.out.println("武打无扎");
session.setAttribute("compareList".toUpperCase(),compareList);
}
application.getRequestDispatcher("/client/clientList.jsp?done=true").forward(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -