title: how do I get this simple angularjs / springmvc application to work?
body: <p>I am trying to create a simple <strong>angularjs/springmvc</strong> "rest" application... -so far, with no success.</p>
  
  <p>In this example, I want to obtain a string value from a spring controller method - i.e., "<strong>getUser()</strong>" and, then, display it on a jsp page - i.e., "<strong>home.jsp</strong>".</p>
  
  <p>after typing "<a href="http://localhost:8084/angtest02/home" rel="nofollow noreferrer">http://localhost:8084/angtest02/home</a>" in the browser, the initial screen displays "user: "...</p>
  
  <p><a href="https://i.stack.imgur.com/jOyz7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jOyz7.png" alt="enter image description here"></a></p>
  
  <p>Then, when I modify the URL to be "<a href="http://localhost:8084/angtest02/home" rel="nofollow noreferrer">http://localhost:8084/angtest02/home</a><strong>/user</strong>" - i.e., in order to invoke the spring controller method, the screen still only displays "user: "  (i.e., instead of the desired "<strong>user: Joseph Blow</strong>")...<br>
  -- But, additionally, presents a dialog that asks: "<em>Do you want to open or save user.json (11 bytes) from localhost</em>"...</p>
  
  <p><a href="https://i.stack.imgur.com/IaNTa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IaNTa.png" alt="enter image description here"></a></p>
  
  <p><em>...Which is NOT what I want.</em>  </p>
  
  <p>Rather, my intention is to have the "<strong>{{user}}</strong>" variable replaced with the value returned by the spring controller method: "<strong>getUser()</strong>".*</p>
  
  <p><em>The image, below, is just to illustrate the location of the "{{user}}" variable on the page.</em></p>
  
  <p><a href="https://i.stack.imgur.com/P88XF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P88XF.png" alt="enter image description here"></a></p>
  
  <p><strong><em>Note</strong>: the spring controller method (i.e., "<strong>getUser()</strong>") is apparently invoked, but, seemingly, not the "<strong>userService</strong>" (i.e., located in app.js)</em></p>
  
  <hr>
  
  <p><strong><em>Below, is my code...</em></strong></p>
  
  <hr>
  
  <p><strong><em>index.jsp (redirects to home.jsp)</em></strong></p>
  
  <pre><code>    &lt;%
        response.sendRedirect("home");
      %&gt;
  </code></pre>
  
  <p><strong><em>home.jsp</em></strong></p>
  
  <pre><code>    &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
      &lt;!doctype html&gt;
      &lt;html&gt;
          &lt;head&gt;
              &lt;title&gt;home page&lt;/title&gt;
              &lt;meta charset="UTF-8"&gt;
              &lt;script type="text/javascript" src="${pageContext.request.contextPath}/webjars/angularjs/1.4.4/angular.js"&gt;&lt;/script&gt;    
              &lt;script type="text/javascript" src="${pageContext.request.contextPath}/webjars/angularjs/1.4.4/angular-route.js"&gt;&lt;/script&gt;  
              &lt;script type="text/javascript" src="${pageContext.request.contextPath}/webjars/angularjs/1.4.4/angular-resource.js"&gt;&lt;/script&gt;  
              &lt;script type="text/javascript" src="resources/js/app.js"&gt;&lt;/script&gt;
  
          &lt;/head&gt;
          &lt;body ng-app="mainApp"&gt;
              &lt;div ng-controller="appController"&gt;
                  &lt;h1&gt;user: {{user}}&lt;/h1&gt;
              &lt;/div&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><strong><em>app.js</em></strong></p>
  
  <pre><code>    /* global angular */
  
      var mainApp = angular.module('mainApp', []);
  
      mainApp.controller('appController', function ($scope, userService) {
          userService.getUser().success(function (data) {
              $scope.user = data;
          });
      });
  
      mainApp.factory('userService', function ($http) {
          var getUser = function () {
              return $http.get('/home/user');
          };
  
          return {
              getUser: getUser
          };
      });
  </code></pre>
  
  <p><strong><em>UserRestController.java</em></strong></p>
  
  <pre><code>    package aaa.bbb.ccc.war;
  
      import javax.servlet.http.HttpSession;
      import org.apache.logging.log4j.LogManager;
      import org.springframework.http.HttpStatus;
      import org.springframework.http.ResponseEntity;
  
      import org.springframework.stereotype.Controller;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
  
      @Controller
      public class UserRestController
      {
          private static final org.apache.logging.log4j.Logger LOG = LogManager.getLogger("UserRestController");
  
          @RequestMapping(value = "/home/user", produces = {"application/json"}, method = RequestMethod.GET)
          public ResponseEntity&lt;String&gt; getUser()
          {
              LOG.info("_______getUser()_______entering...");
  
              return new ResponseEntity&lt;&gt;("Joesph Blow", HttpStatus.OK);
          }
  
  
          //***seems I need this "init" method, in order to "land" on the "home.jsp" page, initially...
          @RequestMapping(value = "/home", method = RequestMethod.GET)
          public String home(HttpSession session)
          {
              LOG.info("_______home()_______entering...");        
              return "home";
          }    
      }
  </code></pre>
  
  <p>FUTHER DETAILS BELOW (IF NEEDED)...</p>
  
  <p><strong><em>web.xml</em></strong></p>
  
  <pre><code>    &lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
               version="3.1"&gt;
          &lt;filter&gt;
              &lt;filter-name&gt;charEncodingFilter&lt;/filter-name&gt;
              &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;
              &lt;init-param&gt;
                  &lt;param-name&gt;encoding&lt;/param-name&gt;
                  &lt;param-value&gt;UTF-8&lt;/param-value&gt;
              &lt;/init-param&gt;
              &lt;init-param&gt;
                  &lt;param-name&gt;forceEncoding&lt;/param-name&gt;
                  &lt;param-value&gt;true&lt;/param-value&gt;
              &lt;/init-param&gt;
          &lt;/filter&gt;
          &lt;filter-mapping&gt;
              &lt;filter-name&gt;charEncodingFilter&lt;/filter-name&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
          &lt;/filter-mapping&gt;
          &lt;listener&gt;
              &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
          &lt;/listener&gt;
          &lt;listener&gt;
              &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
          &lt;/listener&gt;    
          &lt;context-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;
                  WEB-INF/spring/applicationContext.xml
              &lt;/param-value&gt;
          &lt;/context-param&gt;
          &lt;servlet&gt;
              &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
              &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
              &lt;init-param&gt;
                  &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
                  &lt;param-value&gt;
                      WEB-INF/spring/applicationContext.xml           
                  &lt;/param-value&gt;
              &lt;/init-param&gt;
              &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
          &lt;/servlet&gt;
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
              &lt;url-pattern&gt;/&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
          &lt;welcome-file-list&gt;
              &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
          &lt;/welcome-file-list&gt;
      &lt;/web-app&gt;
  </code></pre>
  
  <p><strong><em>project folder structure looks like this</em></strong></p>
  
  <pre><code>    angtest02
      |
      +-src
          |
          +-main
              |
              +-java
              |   |
              |   +-aaa.bbb.ccc.war
              |       |
              |       +-UserRestController.java
              |
              +-resources
              |   |
              |   +-log4j2.xml
              |
              +-webapp
                  |
                  +-META-INF
                  |   |
                  |   +-context.xml
                  |
                  +-resources
                  |   |
                  |   +-js
                  |       |
                  |       +-app.js
                  |
                  +-WEB-INF
                      |
                      +-spring
                      |   |
                      |   +-applicationContext.xml
                      | 
                      +-views
                          |
                          +-home.jsp
  </code></pre>
  
  <p><strong><em>applicationContext.xml</em></strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:p="http://www.springframework.org/schema/p"
                   xmlns:context="http://www.springframework.org/schema/context"
                   xmlns:jee="http://www.springframework.org/schema/jee"
                   xmlns:task="http://www.springframework.org/schema/task"
                   xmlns:tx="http://www.springframework.org/schema/tx"
                   xmlns:ws="http://jax-ws.dev.java.net/spring/core"
                   xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
                   xmlns:mvc="http://www.springframework.org/schema/mvc" 
                   xmlns:util="http://www.springframework.org/schema/util"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee              http://java.sun.com/xml/ns/javaee/beans_1_0.xsd
                                      http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans.xsd     
                                      http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context.xsd     
                                      http://www.springframework.org/schema/jee       http://www.springframework.org/schema/jee/spring-jee.xsd     
                                      http://www.springframework.org/schema/tx        http://www.springframework.org/schema/tx/spring-tx.xsd
                                      http://www.springframework.org/schema/task      http://www.springframework.org/schema/task/spring-task.xsd                                
                                      http://www.springframework.org/schema/util      http://www.springframework.org/schema/util/spring-util.xsd                                                                                                                                                                                                                                                                                                                                                                                                        
                                      http://jax-ws.dev.java.net/spring/core          http://jax-ws.dev.java.net/spring/core.xsd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
                                      http://jax-ws.dev.java.net/spring/servlet       http://jax-ws.dev.java.net/spring/servlet.xsd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                      http://www.springframework.org/schema/mvc       http://www.springframework.org/schema/mvc/spring-mvc.xsd"&gt;
  
  
          &lt;context:component-scan base-package="aaa.bbb.ccc.**" /&gt;
  
          &lt;mvc:annotation-driven/&gt;
          &lt;context:annotation-config/&gt;
  
          &lt;tx:annotation-driven/&gt;
  
          &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
              &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;        
              &lt;beans:property name="suffix" value=".jsp" /&gt;
          &lt;/beans:bean&gt;   
  
          &lt;mvc:resources mapping="/static/**" location="/static/" /&gt;
          &lt;mvc:resources mapping="/webjars/**" location="/webjars/" /&gt;
          &lt;mvc:resources mapping="/assets/**" location="/assets/" /&gt;
          &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;    
  
      &lt;/beans:beans&gt;
  </code></pre>
  
  <p><strong><em>pom.xml</em></strong></p>
  
  <pre><code>    &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
          &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
          &lt;groupId&gt;aaa.bbb.ccc&lt;/groupId&gt;
          &lt;artifactId&gt;angtest02&lt;/artifactId&gt;
          &lt;version&gt;1&lt;/version&gt;
          &lt;packaging&gt;war&lt;/packaging&gt;
          &lt;name&gt;angtest02&lt;/name&gt;
          &lt;properties&gt;
              &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
              &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;/properties&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax&lt;/groupId&gt;
                  &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
                  &lt;version&gt;6.0&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;junit&lt;/groupId&gt;
                  &lt;artifactId&gt;junit&lt;/artifactId&gt;
                  &lt;version&gt;4.11&lt;/version&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
              &lt;/dependency&gt;     
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                  &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
                  &lt;version&gt;3.1.0&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
                  &lt;artifactId&gt;javax.servlet.jsp-api&lt;/artifactId&gt;
                  &lt;version&gt;2.3.1&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                  &lt;artifactId&gt;jstl&lt;/artifactId&gt;
                  &lt;version&gt;1.2&lt;/version&gt;
              &lt;/dependency&gt;   
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
                  &lt;version&gt;4.2.1.RELEASE&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
                  &lt;version&gt;4.2.1.RELEASE&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
                  &lt;version&gt;4.2.1.RELEASE&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
                  &lt;version&gt;4.2.1.RELEASE&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
                  &lt;version&gt;4.2.1.RELEASE&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
                  &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
                  &lt;version&gt;2.4&lt;/version&gt;
              &lt;/dependency&gt;   
              &lt;dependency&gt;
                  &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
                  &lt;artifactId&gt;jackson-core-asl&lt;/artifactId&gt;
                  &lt;version&gt;1.9.13&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
                  &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
                  &lt;version&gt;1.9.13&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
                  &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
                  &lt;version&gt;2.3.4&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
                  &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
                  &lt;version&gt;2.3.4&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.fasterxml.jackson.datatype&lt;/groupId&gt;
                  &lt;artifactId&gt;jackson-datatype-hibernate4&lt;/artifactId&gt;
                  &lt;version&gt;2.3.4&lt;/version&gt;
                  &lt;type&gt;jar&lt;/type&gt;
              &lt;/dependency&gt;     
              &lt;dependency&gt;
                  &lt;groupId&gt;org.webjars&lt;/groupId&gt;
                  &lt;artifactId&gt;bootstrap&lt;/artifactId&gt;
                  &lt;version&gt;3.3.1&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.webjars&lt;/groupId&gt;
                  &lt;artifactId&gt;datatables&lt;/artifactId&gt;
                  &lt;version&gt;1.10.7&lt;/version&gt;
              &lt;/dependency&gt;   
              &lt;dependency&gt;
                  &lt;groupId&gt;org.webjars&lt;/groupId&gt;
                  &lt;artifactId&gt;angularjs&lt;/artifactId&gt;
                  &lt;version&gt;1.4.4&lt;/version&gt;
              &lt;/dependency&gt;                      
              &lt;dependency&gt;
                  &lt;groupId&gt;org.webjars&lt;/groupId&gt;
                  &lt;artifactId&gt;ng-grid&lt;/artifactId&gt;
                  &lt;version&gt;2.0.14&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.webjars&lt;/groupId&gt;
                  &lt;artifactId&gt;jquery&lt;/artifactId&gt;
                  &lt;version&gt;2.1.4&lt;/version&gt;
              &lt;/dependency&gt;                 
          &lt;/dependencies&gt;
          &lt;build&gt;
              &lt;finalName&gt;${project.name}-${project.version}&lt;/finalName&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                      &lt;version&gt;3.1&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;source&gt;1.7&lt;/source&gt;
                          &lt;target&gt;1.7&lt;/target&gt;
                          &lt;showDeprecation&gt;true&lt;/showDeprecation&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;    
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.3&lt;/version&gt;
                  &lt;/plugin&gt;            
              &lt;/plugins&gt;
          &lt;/build&gt;
      &lt;/project&gt;
  </code></pre>