Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Spring MVC Beginner's Guide
  • Table Of Contents Toc
  • Feedback & Rating feedback
Spring MVC Beginner's Guide

Spring MVC Beginner's Guide

By : Ganeshan
4.3 (30)
close
close
Spring MVC Beginner's Guide

Spring MVC Beginner's Guide

4.3 (30)
By: Ganeshan

Overview of this book

A step-by-step pragmatic approach to web application development using Spring MVC, with relevant screenshots and concise explanations. This book is aimed at helping Java developers who want to teach themselves Spring MVC, even if they have no previous experience with Spring MVC. It would be helpful to have a bit of familiarity with basic servlet programming concepts, but no prior experience is required.
Table of Contents (14 chapters)
close
close
13
Index

Time for action – consuming REST web services via Ajax

In order to consume Rest web services via Ajax, perform the following steps:

  1. Add a JavaScript file named controllers.js under the directory /src/main/webapp/resources/js/; then, add the following code snippets to it and save it:
    var cartApp = angular.module('cartApp', []);
    
    cartApp.controller('cartCtrl',  function ($scope, $http) {
      
      $scope.refreshCart = function(cartId) {
        $http.get('/webstore/rest/cart/'+$scope.cartId)
        .success(function(data) {
          $scope.cart = data;
        });
      };
      
      $scope.clearCart = function() {
        $http.delete('/webstore/rest/cart/'+$scope.cartId)
        .success($scope.refreshCart($scope.cartId));
        
      };
      
      $scope.initCartId = function(cartId) {
        $scope.cartId=cartId;
        $scope.refreshCart($scope.cartId);
      };
      
      $scope.addToCart = function(productId) {
        $http.put('/webstore/rest/cart/add/'+productId)
        .success(function(data)...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY