springmvc 的跨域访问

为什么跨域访问,就不多说原因了。只说解决方式。

1.服务端跨域,前端有个jsonp,用来解决跨域。在ajax提交的时候,content-type设置为jsonp就可以了。其他的跟json没区别。

2.服务器端解决跨域。

    第一种:服务端解决跨域的话,如果用的是spring4.2以上,在要访问的Controller上添加@CrossOrigin,基本解决跨域的问题。

   第二种:配置filter,具体的配置搜一下,我也没这样用。放的太开了。

    现在说一下问题:在第一种的情况下,添加了@crossOrigin注解后,但是,前端还是提示跨域访问限制。如:

    is therefore not allowed access. The response had HTTP status code 403;

    No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin;

    后端也有相应的错误提示:

    the request was rejected because no multipart boundary was found;

出现这样的问题是因为没有配置接收的方式,在requestMapping上配置访问方式就好。


猜你喜欢

转载自blog.csdn.net/m0_37626203/article/details/80593391