为什么'/ test'转到'localhost:8080 / test'而不是'localhost:8080 / rootcontext / test'

时间:2015-02-22 08:58:22

标签: java eclipse angularjs web

我在eclipse中创建了一个动态Web项目,使用maven 3 .i从客户端的angularjs和spring and spring security作为后端技术使用。

当我运行项目时,它正确地重定向到根上下文和登录页面,

但是当我想运行这个javascript:

angular.module('common')
.controller('BaseFormCtrl', ['$scope', '$http', function ($scope, $http) {

           $scope.login = function (username, password) {

        $http({
            method: 'POST',
            url: '/authenticate',
            data: postData,
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
                "X-Login-Ajax-call": 'true'
            }
        })
        .then(function(response) {
            if (response.data == 'ok') {
                window.alert("login success");
            }
            else {
                window.alert("login faild");
            }
        });
    }


}])

它返回此错误:

POST http://localhost:8080/authenticate 404 (Not Found)

但我希望它称之为:http://localhost:8080/avl-web/authenticate

avl-web是我的根上下文

1 个答案:

答案 0 :(得分:1)

提出' /'无论您的根上下文是什么,在URL开头都将转到主机。

'/avi-web/authenticate'

包含根上下文将允许您使用这样的绝对URL。