Search code examples
javascriptangularjsspring-mvchttp-status-code-406

406 err while data returning from spring java controller to angularjs service


am stuck at geting data from controller to angular service please check my code any body suggest me what to do

thanks in advance

pom.xml

  <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.7.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.7.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.7.4</version>
        </dependency>

java controller

@RequestMapping(value="/getAlluserDetails", method=RequestMethod.GET)
@ResponseBody
public List<Map<String, Object>> getAllUserDetails(){
    System.out.println("getAllUserDetails");
    ModelMap mav =new ModelMap();
    List<Map<String, Object>> listofusers = userServices.getUserData();
    System.out.println("listofusers : "+listofusers);
    return listofusers;

index.html

app.service("myServices",function($q,$http,$log) {
	var deffered = $q.defer();
	var responseData;
	this.getUsers = function(){
		return $http({
			method:'GET',
			url:'getAlluserDetails.htm'
//			data: JSON.stringify(search)
		}).then(function(response){
//			$scope.users = response.data;
			$log.info("samei"+response);
			return response;
		},function(reason){
			$log.info("samei 123err"+reason);
			return reason;
		});

	};
 <!doctype html>
<html ng-app="app">
<head lang="en">
<meta charset="utf-8">
<title>AngularJS Routing</title>
<script src="http://code.angularjs.org/1.2.13/angular.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
 <script type="text/javascript" src="resources/scripts/main.js"></script>
<script type="text/javascript" src="resources/static/services/services.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
 <link rel="stylesheet" href="resources/static/css/style.css">
 <script type="text/javascript" src="resources/static/controllers/LoginController.js"></script>
 <script type="text/javascript" src="resources/static/controllers/UserController.js"></script>
 <script type="text/javascript" src="resources/static/controllers/GetUserDetailsController.js"></script>
</head>
<body>
<div class="container" width="100px">
      <h2>Medhassu user data upload</h2>
      <div ui-view></div>
 </div>

in my browser

response header

Content-Language
en Content-Length
1067 Content-Type
text/html;charset=utf-8 Date
Sun, 25 Feb 2018 15:49:04 GMT Server
Apache-Coyote/1.1

request header

Accept
application/json, text/plain, / Accept-Encoding gzip, deflate Accept-Language en-US,en;q=0.5 Connection
keep-alive Host
localhost:8081 Referer http://localhost:8081/UserRegistration/ User-Agent
Mozilla/5.0 (Windows NT 6.3; W…) Gecko/20100101 Firefox/58.0


Solution

  • None of the converters or dependencies helped from 406 status i have just converted to Gson in my spring controller before my data is returning to angularjs service (which should be done by Spring instead of me).This is what i have did

    if any one have better solution then this, please let me know