当前位置:网站首页>A solution to cross domain problems
A solution to cross domain problems
2022-06-26 02:00:00 【Murong Tianyu】
Learning today angular When , In order to test post Request , When writing interface , newspaper 403, An online search is a cross domain error
see network The interface in header Of Request Method The type is options
PS.angular Yes post Requested packaging options, And first send a request to confirm the survival status of the server , Then go again. Post Request .
1. add to filter class
package cn.murong.web.aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import javax.servlet.annotation.WebFilter;
@Order(1) // The order of slice loading ,1 Represents the first load
@WebFilter(filterName =“AccessControlAllowOrigin”,urlPatterns = {"*"})
public class AccessControlAllowOriginFilter implements Filter {
public static final Logger log = LoggerFactory.getLogger(AccessControlAllowOriginFilter.class);
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,ServletException{
HttpServletResponse response = (HttpServletResponse)res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE, PATCH");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
response.setHeader("Access-Control-Expose-Headers", "Location");
chain.doFilter(req, response);
}
public void init (FilterConfig filterConfig){
}
public void destroy(){
}
}
2. In starting the class Add scan
@MapperScan(“cn.murong.persistence.mapper”)
@ServletComponentScan(basePackages = “cn.murong.web.aspect”)// Add scanned filter Of java package
@SpringBootApplication
public class TimeManageApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(TimeManageApplication.class, args);
ContextUtils.setApplicationContext(context);
}
}
边栏推荐
- shell学习记录(四)
- Show spirit chenzitong was invited to be the chief experience officer of the global finals of the sixth season perfect children's model
- Reverse output an integer
- Chinese and English instructions of collagen enzyme Worthington
- 秀场精灵陈梓桐 受邀担任第六季完美童模全球总决赛首席体验官
- Postman斷言對應脚本的解釋
- Difference between app test and web test
- Dazhou suggested that we media bloggers do these four things in the early stage
- Redis-SDS
- Dataframe converts the data type of a column
猜你喜欢

Chrome浏览器开发者工具使用

通俗易懂C語言關鍵字static

cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network

What happens from entering a web address in the browser's input box to seeing the contents of the web page?

recv & send

biggan:large scale gan training for high fidelity natural image synthesis

V4L2+QT视频优化策略

Postman斷言對應脚本的解釋

一分钟了解同步、异步、阻塞和非阻塞的区别

Abnova actn4 DNA probe solution
随机推荐
PTA class a simulated fifth bomb: 1148-1151
元气少女王钰洁 受邀担任第六季完美童模全球总决赛代言人
Redis7.0 installation steps
shell curl 执行脚本,带传参数,自定义参数
biggan:large scale gan training for high fidelity natural image synthesis
GUN make (2) 总述
通俗易懂C語言關鍵字static
Talking about interface test (I)
Detailed explanation of memory leak check tools
readv & writev
Postman斷言對應脚本的解釋
PTA class a simulated ninth bullet: 1114-1117
NDK20b FFmpeg4.2.2 编译和集成
Finding the sum of N multiplications
buffer
Redis-SDS
Data analysis - similarities and differences between C-end and b-end data analysis
Perfdog
V4L2+QT视频优化策略
分布式系统(二)分布式事务的理解