1.angular使用json格式上传参数,而springMVC使用x-www-form-urlencoded格式获取参数。
采用修改前端的方法进行兼容,body修改为 xx=aa&yy=bb的形式,加入http头 application/x-www-form-urlencoded
const body = 'userId=' + this.userId + '&token=' + this.token; this.http.post(this.uriService.baseUrl + this.uriService.loginByToken, body, { headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'), })
2.跨域请求中,tomcat会因为 Access-Control-Allow-Origin选项,没有正确设置出现403的情况,后台没有任何日志产生,采用nginx转发请求到tomcat,nginx不需要加入http文件头处理,在tomcat侧处理,采用官方推荐的方法,在web.xml添加filter,其中org.apache.catalina.filters.CorsFilter不需要添加maven依赖。
<filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> </filter> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>