📄 modifycount.java
字号:
package com.xaccp.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Hashtable;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.xaccp.business.ShopCar;
import com.xaccp.entity.Product;
public class ModifyCount extends HttpServlet {
public ModifyCount() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String[] prodId = request.getParameterValues("id");// 获取商品编号列表
String[] prodCount = request.getParameterValues("count");// 获取修改后的数量列表
HttpSession session = request.getSession();
Object obj = session.getAttribute("shopCar");
ShopCar shopCar = (ShopCar) obj;
Hashtable<String, Product> table = shopCar.getProductList();
for (int i = 0; i < prodId.length; i++) {
Product prod = (Product) table.get(prodId[i]);
prod.setProdCount(Integer.parseInt(prodCount[i]));
}
session.setAttribute("shopCar", shopCar);
response.sendRedirect("productCar.jsp");
out.flush();
out.close();
}
public void init() throws ServletException {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -