2017-04-05 13 views
-1

私はEclipseを作成しました。Eclipseでローカルにプロジェクトを実行すると、ユーザーがボタンをクリックするとスクリプトが実行されます今すぐ注文。この後、カートアイテムには少なくとも1つの製品があります。ローカルとサーバーの実行の間に予期しない不一致が発生しました

Azureでプロジェクトをアップロードしました。ボタンの操作今すぐ注文は正しく動作しません。 cart.jspファイルで

viewProduct.jsp

<!-- Import spring text --> 
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<%@include file="/WEB-INF/views/template/header.jsp"%> 


<div class="container-wrapper"> 
    <div class="container"> 
     <div class="page-header"> 
      <h1>Product Detail</h1> 

      <p class="lead">Here is the detail information of the product</p> 
     </div> 

     <!-- Grid system from Bootstrap --> 
     <div class="container" ng-app="cartApp"> 
      <div class="row"> 
       <div class="col-md-5"> 
        <img 
         src="<c:url value="/resources/images/${product.productId}.png" /> " 
         alt="image" style="width: 100%" /> 
       </div> 
       <div class="col-md-5"> 
        <h3>${product.productName}</h3> 
        <p>${product.productDescription}</p> 
        <p> 
         <strong>Manufacture</strong> : ${product.productManufacture} 
        </p> 
        <p> 
         <strong>Category</strong> : ${product.productCategory} 
        </p> 
        <p> 
         <strong>Condition</strong> : ${product.productCondition} 
        </p> 
        <p>${product.productPrice}USD</p> 

        <br> 

        <c:set var="role" scope="page" value="${param.role}" /> 
        <c:set var="url" scope="page" value="/product/productList" /> 
        <!-- if the user is admin we change the back page for the following "back" button --> 
        <c:if test="${role='admin'}"> 
         <c:set var="url" scope="page" value="/admin/productInventory" /> 
        </c:if> 

        <p ng-controller="cartCtrl"> 
         <a href="<c:url value="${url}" />" class="btn btn-default">Back</a> 
         <!-- we use the angular funtction (#) --> 
         <a href="#" class="btn btn-warning btn-large" 
          ng-click="addToCart('${product.productId}')"><span 
          class="glyphicon glyphicon-shopping-cart"></span>Order Now</a> 

         <a href="<spring:url value="/customer/cart" />" class="btn btn-default"><span 
          class="glyphicon glyphicon-hand-right"></span>View Cart</a> 
        </p> 
       </div> 
      </div> 
     </div> 

    </div> 
</div> 

<script src="<c:url value="/resources/js/controller.js" /> "></script> 
<%@include file="/WEB-INF/views/template/footer.jsp"%> 

私もcontroller.jsからclearCartを()を実行してみてください。また、コードは実行されません。

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 
<%@include file="/WEB-INF/views/template/header.jsp" %> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script> 
<script src="<c:url value="/resources/js/controller.js" /> "></script> 

<div class="container-wrapper"> 
    <div class="container"> 
     <section> 
      <div class="jumbotron"> 
       <div class="container"> 
        <h1>Cart</h1> 

        <p>All the selected products in your shopping cart</p> 
       </div> 
      </div> 
     </section> 

     <section class="container" ng-app="cartApp"> 
      <div ng-controller = "cartCtrl" ng-init="initCartId('${cartId}')"> 
      <div> 
       <a class="btn btn-danger pull-left" ng-click="clearCart()"><span 
         class="glyphicon glyphicon-remove-sign"></span>Clear Cart</a> 
       <a href="<spring:url value="/order/${cartId}"/>" 
        class="btn btn-success pull-right"><span class="glyphicon-shopping-cart glyphicon"></span> Check out 
       </a> 
      </div> 

      <table class="table table-hover"> 
       <tr> 
        <th>Product</th> 
        <th>Unit Price</th> 
        <th>Quantity</th> 
        <th>Price</th> 
        <th>Action</th> 
       </tr> 
       <tr ng-repeat = "item in cart.cartItems"> 
        <td>{{item.product.productName}}</td> 
        <td>{{item.product.productPrice}}</td> 
        <td>{{item.quantity}}</td> 
        <td>{{item.totalPrice}}</td> 
        <td><a href="#" class="label label-danger" ng-click="removeFromCart(item.product.productId)"> 
         <span class="glyphicon glyphicon-remove"></span>remove</a></td> 
       </tr> 
       <tr> 
        <th></th> 
        <th></th> 
        <th>Grand Total</th> 
        <th>{{calGrandTotal()}}</th> 
        <th></th> 
       </tr> 
      </table> 

      <a href="<spring:url value="/" />" class="btn btn-default">Continue Shopping</a> 
      </div> 
     </section> 

    </div> 
</div> 


<%@include file="/WEB-INF/views/template/footer.jsp" %> 

controller.js

var cartApp = angular.module ("cartApp", []); 

cartApp.controller("cartCtrl", function ($scope, $http){ 

    $scope.refreshCart = function() { 
     $http.get('/eMusicStore/rest/cart/'+$scope.cartId).success(function (data) { 
      $scope.cart=data; 
     }); 
    }; 

    $scope.clearCart = function() { 
     $http.delete('/eMusicStore/rest/cart/'+$scope.cartId).success($scope.refreshCart()); 
    }; 

    $scope.initCartId = function (cartId) { 
     $scope.cartId = cartId; 
     $scope.refreshCart(cartId); 
    }; 

    $scope.addToCart = function (productId) { 
     $http.put('/eMusicStore/rest/cart/add/'+productId).success(function() { 
      alert("Product successfully added to the cart!") 
     }); 
    }; 

    $scope.removeFromCart = function (productId) { 
     $http.put('/eMusicStore/rest/cart/remove/'+productId).success(function (data) { 
      $scope.refreshCart(); 
     }); 
    }; 

    $scope.calGrandTotal = function() { 
     var grandTotal=0; 

     for (var i=0; i<$scope.cart.cartItems.length; i++) { 
      grandTotal+=$scope.cart.cartItems[i].totalPrice; 
     } 

     return grandTotal; 
    }; 
}); 
+0

「正しく動作しません」とはどういう意味ですか? **どのように**正確には機能しませんか?エラーメッセージが表示されますか(ブラウザのコンソールでサーバーログに記録されます) –

+0

@JozefChocholacekエラーはありません。 ** Order Now **をクリックすると、** addToCart **機能で表示されている警告が表示されないため、角度コードが実行されません。ですから、角度コードは決して実行されないと思います。 –

+0

** addToCart **関数の最初の行に 'alert'を追加して、それが呼び出されたかどうかを確認できますか? –

答えて

0

HTTPエラー応答をログに記録するには、次のコードを試してみてください。

$http.put('/eMusicStore/rest/cart/remove/'+productId).success(function (data) { 
    $scope.refreshCart(); 
}).error(function (data, status, header, config) { 
    console.log(data);  
}); 
+0

このコードはすべてe-courseからのものです。しかし、私はいくつかの問題があると思います。私はinitCartIdでrefreshCartに引数(cartId)がありますが、refreshCartの定義に引数がないことがわかります!この後、関数calGrandTotalには引数がありません。では、この関数がgrandTotalの結果をどのように見つけようとしていますか?私が言うことの何かが当てはまらない場合は、私はネーミングをお願いしたいと思いますが、私はAngularでは本当に後輩です。 –

+0

あまりにも多くの試行(およびカートの作成の開始時にいくつかのプロジェクトに戻る)の後、現在のエラーがあります。 ** SEVERE:パス[/ eMusicStore]のコンテキスト内のサーブレット[SpringMVC]のServlet.service()が例外をスローしました[ハンドラの処理に失敗しました。入れ子にされた例外は根本的な原因でjava.lang.StackOverflowErrorです。 java.lang.StackOverflowError ** 私は一週間前にこのエラーを尋ねました。誰かが私にリンクをくれましたが、何がうまくいかないのか分かりません。 –

関連する問題