1

This is my situation, I have a project in Netbeans 8.2, in the html, here call angularjs, but when need to call java controller from angular we receive a "not found" in chrome debug, in the factory with the $http send the "url", but I dont can to call java controller.

-- This is code html

<div data-ng-app="myApp">
<div data-ng-controller="MyController">
<button data-ng-click="getDataFromServer()">Test Angularjs</button>
</div>
</div>

-- This is the code in angularjs (this is a File.js)

var app = angular
        .module('myApp', ['ngRoute', 'ngResource'])

        .controller('MyController', function ($scope, $service, $http, $resource) {          
            $scope.getDataFromServer = function () {

                $service.JS_STST_GetData();
            }

        })// end controller    
.factory(
        '$service',
        function ($http) {
            return {
                JS_STST_GetData: function (){
                    $http({
                        method: 'POST',
                        url: 'TestMaping',
                        headers: {
                            'Content-Type': 'application/json'
                        }
                    }).then(_success, _error);
                },

-- This is the Java Controller Code

@Controller
public class VerController {

    @RequestMapping(value="/TestMaping", method = RequestMethod.POST)
    public String TEST(Model model){
        return "Test";
    }

    @RequestMapping(method = RequestMethod.GET)
    public String otroMetodo(Model model){
        return "index";
    }
}
2

1 Answer 1

5

You are making a POST call while your controller request mapping is of method type GET for url /TestMaping. Please correct it & try.

Sign up to request clarification or add additional context in comments.

9 Comments

Thanks for the observation, but not is the solution.
Try to put a full URL in your controller (loclahost:port...) rather than just /TestMapping
Thanks, but it´s doesn´t work, this is the message:angular.js:12407 POST localhost:8080/EjSpringMVC/TestMaping 404 (Not Found). I dont know if I need to configured something.
Just to ensure that the controller is being initialized, please debug on constructor OR print a statement from the constructor of VerController
how to define the contructor, because i was based in a example and not remember has a contructor .
|

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.