Я новичок в ajax, и мне нравится, как он может делать вещи асинхронно без перезагрузки страницы.Если бы я хотел обновить общее количество товаров в корзине, не нажимая кнопку «обновить», это можно сделать с помощью объекта XMLHttpRequest.Спасибо за помощь.
<%
ShoppingCart cart = (ShoppingCart)session.getAttribute("cart");
if(cart==null){
response.sendRedirect("manageCart.jsp");
}else{
//We have the cart, let's update it
int itemCount = cart.getItemCount();
int quant = 0;
for(int i=itemCount-1; i>=0; i--){
try{
//User may have erased quantity or entered non-numeric value
quant = new Integer(request.getParameter("item" + i)).intValue();
}catch(NumberFormatException nfe){
quant = 1;
}
//Get the next Item
Item item = cart.getItem(i);
//Set its quantity
item.setQuantity(quant);
if(request.getParameter("remove" + i)!=null){
//Remove checkbox checked
cart.removeItem(i);
}
}
//Put the cart back in the session
session.setAttribute("cart",cart);
//go look at it!
response.sendRedirect("manageCart.jsp");
}
%>