Here is my app.js:
var loginModule = angular.module('loginModule',[]);
loginModule.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
}]);
loginModule.controller('loginCtrl',function ($scope,$http,$parse){
$scope.signin_user = {name:"",password:""};
$scope.errors = [];
$scope.submit = function(){
if($scope.login_form.$valid){
var data ="name="+$scope.signin_user.name+"&password="+$scope.signin_user.password;
$http({
method:'post',
url:'${ctx}/login',
data:data
})
.success(function(data,status){
console.log(data);
})
.error(function(data,status){
console.log('status:'+status);
});
}
};
});
In login.jsp I'm using jstl to get my web root,here is my tag.jsp, in login.jsp just include this file,which can use ${ctx} to get the web root.
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath }" ></c:set>
But I don't understand what happend in the angularjs, using $htpp.post(url:'${ctx}/login'),just like app.js file.
And I use chrome developer tools to watch request url,I find the request url like this picture: https://i.sstatic.net/eWgs2.png
the url was append other unreadable code.
I hope someone can fix it,thank all. If you can't see the picture, I would tell you in chrome developer tools the request url is 'localhost:8080/cloudaction/$%7Bctx%7D/login '