-
Servlet生命周期查看全部
-
Servlet结构查看全部
-
创建一个Servlet步骤: 1.新建一个Java类,继承“javax.servlet.http.HttpServlet” 2.重写“doGet()”方法和“doPost()”方法 3.在“web.xml”中注册Servlet查看全部
-
path变量访问Servlet路径查看全部
-
ok查看全部
-
Tomcat容器等级查看全部
-
servlet概念查看全部
-
sevlet是JSP的前身查看全部
-
jsp与servlet对象的对应关系查看全部
-
isAccept不是改成了flag了吗?为什么后面还有isAccept.equals()什么什么的?查看全部
-
servlet 生命周期查看全部
-
显示购物车 @1.CartServlet.java public void doPost(){ if(action.equals("delete")) //如果是执行删除购物车中的商品 { if(deleteFromCart(request,response)) { request.getRequestDispatcher("/cart.jsp").forward(request, response); } else { request.getRequestDispatcher("/cart.jsp").forward(request, response); } } } //从购物车中删除商品 private boolean deleteFromCart() { String id = request.getParameter("id"); Cart cart = (Cart)request.getSession().getAttribute("cart"); Items item = idao.getItemsById(Integer.parseInt(id)); if(cart.removeGoodsFromCart(item)) { return true; } else { return false; } } @2.cart.jsp <a href="servlet/CartServlet?action=delete&id=<%=i.getId()%>" onclick="delcfm();">删除</a> <script language="javascript"> function delcfm() { if (!confirm("确认要删除?")) { window.event.returnValue = false; } } </script>查看全部
-
@2.cart.jsp <% //首先判断session中是否有购物车对象 if(request.getSession().getAttribute("cart")!=null) { %> <!-- 循环的开始 --> <% Cart cart = (Cart)request.getSession().getAttribute("cart"); HashMap<Items,Integer> goods = cart.getGoods(); Set<Items> items = goods.keySet(); Iterator<Items> it = items.iterator(); while(it.hasNext()) { Items i = it.next(); %> <tr name="products" id="product_id_1"> <td class="thumb"><img src="images/<%=i.getPicture()%>" /><a href=""><%=i.getName()%></a></td> <td class="number"><%=i.getPrice() %></td> <td class="price" id="price_id_1"> <span><%=i.getPrice()*goods.get(i) %></span> <input type="hidden" value="" /> </td> <td class="number"> <%=goods.get(i)%> </td> </tr> <% } %> <div class="total"><span id="total">总计:<%=cart.getTotalPrice() %>¥</span></div> <% } %>查看全部
-
@3.details.jsp 购买数量:<span id="sub" onclick="sub();">-</span><input type="text" id="number" name="number" value="1" size="2"/><span id="add" onclick="add();">+</span> <script type="text/javascript"> function add() { var num = parseInt(document.getElementById("number").value); if(num<100) { document.getElementById("number").value = ++num; } } function sub() { var num = parseInt(document.getElementById("number").value); if(num>1) { document.getElementById("number").value = --num; } } </script>查看全部
-
显示购物车 @1.CartServlet.java public void doPost(){ response.setContentType("text/html;charset=utf-8"); if(request.getParameter("action")!=null) { this.action = request.getParameter("action"); if(action.equals("show"))//如果是显示购物车 { request.getRequestDispatcher("/cart.jsp").forward(request, response); } } }查看全部
举报
0/150
提交
取消