-1
我是新来的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");
}
%>
这个问题太宽泛了。通过教程来掌握基本概念。把你的项目放在一边,制定一些基本的教程/例子。这是一个很好的起点:http://stackoverflow.com/questions/4112686/update-current-page-with-a-servlet/4113258#4113258 – BalusC 2011-05-13 19:59:42