前台加请求头token,后台接收

前台Ajax

$.ajax({
            type: "post",
            url: areaComp,
            dataType: "json",
            contentType: "application/json",
            data: data,
            async: false,
                //再次添加头部信息
            beforeSend: function(request) {
                request.setRequestHeader("token", token);
            },
            success: function (data){})

后台接收

ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String token=request.getHeader("token");

猜你喜欢

转载自www.cnblogs.com/gaomanito/p/10684691.html