Below I will share with you an article using SpringMVC filters to solve the problem of vue cross-domain requests. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together
I have written before about how to solve cross-domain requests through annotations. You need to use annotations in the control class every time. This time, we solved it through the interceptor of springmvc:
The class HandlerInterceptor that inherits SpringMVC overrides the preHandle method. This method will be called before reaching controll, as follows
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "*"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); response.setHeader("Access-Control-Allow-Credentials","true"); //是否允许浏览器携带用户身份信息(cookie) return true; }
springmvc configuration is as follows:
<mvc:interceptors > <!--过滤所有请求,处理跨域请求问题--> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="com.jzy.interceptor.CommonInterceptor"></bean> </mvc:interceptor> </mvc:interceptors >
This can solve the limitation of cross-domain requests when SSM VUE is separated from the front and back ends.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
About explaining in detail the use of take in redux-saga
How to implement breakpoints in Visual Studio Code Debugging Vue
How to add, delete and modify query methods through tables in angularJs
The above is the detailed content of Use SpringMVC to solve vue cross-domain requests. For more information, please follow other related articles on the PHP Chinese website!