0

So I have my angular javascript as

    var app = angular.module('app', []);
    app.controller('controller', function($scope, $http) {
        $http.get('http://localhost:8080/core/students.json')
                .success(function(data) {
                    $scope.user = data;
                });
    });

and my rest controller with

@RestController
public class StudentRestController {

@RequestMapping(value = "/students", produces = { "application/json" }, method =      RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public Student getStudent() {
    // return studentService.getStudentByUserName(userName);
    Student s = new Student();
    s.setUserName("userName");
    s.setEmailAddress("email");
    return s;
}
}

but for some reason, the javascript ajax request isn't hitting the method getStudent(). Why is this? I get a console error

"GET http://localhost:8080/core/students.json 404 (Not Found)"

ordinary button url calls work as expected

2 Answers 2

1

change angularjs app as

var app = angular.module('app', []);
app.controller('controller', [ "$scope", "$http", function($scope, $http) {
    $http.get("http://localhost:8080/students").success(function(data) {
        $scope.user = data;
    });
} ]);

that holds if ur web.xml

<servlet-mapping>
        <servlet-name> dispatcherServlet </servlet-name>
        <url-pattern> * </url-pattern>
    </servlet-mapping>
Sign up to request clarification or add additional context in comments.

Comments

0

You are defining "/students" on the @RequestMapping, then your URL should be ".../core/students".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.