(十九)清空購物車


案例3-對購物車進行操作(清空購物車)
步驟分析:
    1.在購物車頁面上,有一個清空購物車的連接
        /store/cart?method=clear
    2.在cartServlet中需要提供 clear
        先獲取購物車
        調用Clearcart方法
        重定向 jsp/cart.jsp頁面
    3.判斷購物車是否為空,
        若為空:提示購物車空空如也
        若不為空:展示

/store/WebContent/jsp/cart.jsp

<!--判斷是否為空-->     

<c:if test="${empty cart.map }">
<h1>購物車空空如也~~趕緊逛逛去!!</h1>
</c:if>

<c:if test="${not empty cart.map }"></>

....
       <div style="text-align:right;margin-top:10px;margin-bottom:10px;"> <a href="${pageContext.request.contextPath }/cart?method=clear" id="clear" class="clear">清空購物車</a> <a href="${pageContext.request.contextPath }/order?method=add"> <input type="submit" width="100" value="提交訂單" name="submit" border="0" style="background: url('${pageContext.request.contextPath}/images/register.gif') no-repeat scroll 0 0 rgba(0, 0, 0, 0); height:35px;width:100px;color:white;"> </a> </div>

com.louis.web.servlet.CartServlet

/*
     * 清空購物車
     * */
    public  String  clear(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //1、獲取購物車
        
        //2、調用購物車的lear方法
        getCart(request).clearCart();
        
        //3、重定向
        response.sendRedirect(request.getContextPath()+"/jsp/cart.jsp");
        return null;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM