0

HTTP Status 406 – Not Acceptable The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation.

controller code

@RequestMapping(value="/welcomes", method = RequestMethod.GET, produces="application/json")
    public @ResponseBody List<UserBean> welcome(@ModelAttribute UserBean userBean, HttpServletResponse response)
    {
        List<UserBean> usernames=new ArrayList<UserBean>();
        usernames = retrievedataservice.findAllUsers(userBean);
        System.out.println(usernames.size());
        return usernames;
    }

angular js code

   <script>
    var app = angular.module('myApp', []);
    app.controller('UserController', function($scope, $http, $location){
        $scope.usernames=[];
            var url = $location.absUrl() + "welcomes";
            $http.get(url).then(function (response) 
            {
                $scope.usernames = response.records;
            },function error(response) 
            {
                $scope.postResultMessage = "Error with status: " +  response.statusText;
            });
    });
    </script>
<table border="1" width="50%" height="50%"> 
    <tr><th>user_name</th><th>phone</th><th>email</th></tr>
     <tr data-ng-repeat="user in usernames">
     <td>{{user.username}}</td>
      <td>{{user.phone}}</td>
       <td>{{user.email}}</td>
       </tr>   
   </table> 

how to send the data from spring controller to angular js controller?

Vignesh_E
  • 167
  • 2
  • 4
  • 15

1 Answers1

1

Try changing the method signature like below.

@RequestMapping(value="/welcomes", method = RequestMethod.GET,produces={"application/json"})
    public @ResponseBody List<UserBean> welcome(UserBean userBean, HttpServletResponse response)

Note that i removed @ModelAttribute and changed produces.

Also ensure that you have jackson or any other json library in your classpath.

If not then add below to pom.xml

<!-- add jackson to support restful API, otherwise the API will return 406 error -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

Refer this thread

Alien
  • 15,141
  • 6
  • 37
  • 57