Java Servlet list.remove不工作

Java Servlet list.remove不工作,java,list,servlets,Java,List,Servlets,我有一个字符串列表。list.add可以正常工作,但是list.remove不能工作。这是我的代码: 公共类CartServlet扩展了HttpServlet{ 私有静态最终长serialVersionUID=1L public List<String> cart = new ArrayList<String>(); public CartServlet() { super(); // TODO Auto-generated constructor stu

我有一个字符串列表。list.add可以正常工作,但是list.remove不能工作。这是我的代码:

公共类CartServlet扩展了HttpServlet{ 私有静态最终长serialVersionUID=1L

public List<String> cart = new ArrayList<String>();
public CartServlet() {
    super();
    // TODO Auto-generated constructor stub
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //cart.forEach(System.out::println);
    request.setAttribute("cart",cart);
    request.getRequestDispatcher("WEB-INF/Cart.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String productAdd = request.getParameter("add");
    String productDelete = request.getParameter("delete");
    if(productAdd != null) {
        cart.add(productAdd);
        //System.out.println(cart.indexOf(productAdd));

    }
    else {
        cart.remove(productDelete);//this is not working
    }
    doGet(request, response);
}

}
public List cart=new ArrayList();
公共CartServlet(){
超级();
//TODO自动生成的构造函数存根
}
受保护的void doGet(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException{
//cart.forEach(System.out::println);
setAttribute(“购物车”,购物车);
getRequestDispatcher(“WEB-INF/Cart.jsp”).forward(请求,响应);
}
受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)引发ServletException、IOException{
字符串productAdd=request.getParameter(“add”);
字符串productDelete=request.getParameter(“delete”);
if(productAdd!=null){
cart.add(productAdd);
//System.out.println(cart.indexOf(productAdd));
}
否则{
cart.remove(productDelete);//这不起作用
}
doGet(请求、响应);
}
}
我补充说:

那么我的购物车是:
我用同样的方法取下,用一个按钮。但是由于某些原因,我正确地获取了productDelete,但是cart.remove(productDelet)不起作用,并且字符串在那里,我感觉字符串不匹配。

remove方法返回布尔值,检查它和列表中的项目。您能给我们显示JSP文件的内容吗?