跳板页
作用:在访问某个页面(如购物车页面)时没有登录,当点击登录,登录成功需要调到该页面
解决思路,在当前页页面(如购物车页面)设置登录链接,调到另一个页面A(A页面需要写个脚本自动调到购物车页面),另一个页面再调回来,但是由于spring secrity 的拦截,由于未登录,经过A页面时会调到登录页,登录成功调到A页面,A页
跨域请求解决方案
两种解决方案Jsonp和Cors(这里介绍后面一种)
//添加到购物车
$scope.addToCart = function(){
//alert('id:'+$scope.sku.id);
//{'withCredentials':true}表示客户端同意cookice操作
$http.get('http://192.168.3.108:9107/cart/addGoodsToCartList.do'+
'?itemId='+ $scope.sku.id + '&num=' + $scope.num,{'withCredentials':true}).success(
function(response){
if(response.success){
location.href='http://192.168.3.108:9107/cart.html';
}else{
alert(response.message);
}
}
);
}
//spring4.2以后推出了注解跨域写法@CrossOrigin(origins="http://192.168.3.108:9105",allowCredentials="true")
//@CrossOrigin(origins="http://192.168.3.108:9105")只写这个默认allowCredentials为true
@RequestMapping("/addGoodsToCartList")
@CrossOrigin(origins="http://192.168.3.108:9105",allowCredentials="true")
public Result addGoodsToCartList(Long itemId,Integer num) {
//跨域请求服务端需要添加两个头信息
//1.Access-Control-Allow-Origin允许跨域请求的地址,如果所有都允许可以将地址配置成*,但是在有cookice操作时不能配置*
//2.Access-Control-Allow-Credentials表示服务端同意cookice操作(客户端也需要同意)当有cookice操作时必须加上这段,如果没有可以不用加
//response.setHeader("Access-Control-Allow-Origin", "http://192.168.3.108:9105");
//response.setHeader("Access-Control-Allow-Credentials", "true");