当前位置:网站首页>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);
}
}
边栏推荐
- Command of gun make (4) rule
- Input 3 integers and output them from large to small
- Dataframe extracts data from a column and converts it into a list
- 胰蛋白酶的化学性质及应用
- Application and chemical properties of elastase
- 反向输出一个整数
- PTA class a simulated second bullet: 1136-1139
- Chrome浏览器开发者工具使用
- Pixel6 unlock bootloader
- Gun make (5) variables in makefile
猜你喜欢

readv & writev

tos cos dscp 区别和作用

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

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

recv & send

王老吉药业“关爱烈日下最可爱的人”公益活动在杭启动

shell学习记录(四)

Differences and functions of TOS cos DSCP

Distributed systems (II) understanding of distributed transactions

recvmsg & sendmsg
随机推荐
V4L2+QT视频优化策略
LeetCode 41 ~ 50
Talking about interface test (I)
Abnova actn4 DNA probe solution
缓存技术之第一次亲密接触
cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
PTA class a simulated sixth bomb: 1156-1159
Is the securities account recommended by qiniu safe?
What happens from entering a web address in the browser's input box to seeing the contents of the web page?
Chemical properties and application of trypsin
GUN make (4) 规则的命令
GUN make (2) 总述
Redis7.0 installation steps
PTA class a simulated 11th bomb: 1124-1131
Wechat circle of friends test point
The 19th - 22nd week of scientific research training - about tnet and memnet
如何为政企移动办公加上一道“安全锁”?
Chrome浏览器开发者工具使用
tos cos dscp 区别和作用
Assertion of postman interface test