📄 deleteoneaction.java
字号:
package shoppingCar;
import java.io.*;
import java.lang.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DeleteOneAction extends HttpServlet{
ArrayList goodsArraylist=null;
Hashtable goodsHashtable=null;
String goodId; //要删除的物品的Id号
int singleCount=0; //购物车内某一种物品的数量
boolean deleteFlag=false;
/**
*doGet
*/
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{
try{
goodId=request.getParameter("goodId");
int i;
goodsArraylist=(ArrayList)(request.getSession().getAttribute("goods"));
for(i=0;i<goodsArraylist.size();i++){
goodsHashtable=(Hashtable)goodsArraylist.get(i);
if( ((String)goodsHashtable.get("goodId")).equals(goodId)){
singleCount=Integer.parseInt(goodsHashtable.get("tradeTimes").toString());
if(singleCount>1){ //数量大于一
goodsHashtable.put("tradeTimes",--singleCount);
goodsArraylist.set(i,goodsHashtable);
request.getSession().setAttribute("goods",goodsArraylist);
deleteFlag=true;
}else{
goodsArraylist.remove(i);
request.getSession().setAttribute("goods",goodsArraylist);
deleteFlag=true;
}
System.out.println(deleteFlag);
break;
}
}
if(i==goodsArraylist.size()){
}
try{
if(deleteFlag){
getServletConfig().getServletContext().getRequestDispatcher
("/shoppingCar.jsp").forward(request,response);
}
}catch(Exception exc){
System.out.println("zhuan fa dao shoppingCar.jsp chu cuo le!!!");
}
}catch(Exception e){
System.out.println("Deleting one good Exception!");
}
}
/**
*doPost
*/
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException
{
doGet( request, response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -