请求没进过滤器。用postman是可以的,也看到设置的返回头了。但是用js请求就不行
@IocBean
public class MyCrossOriginFilter implements ActionFilter {
private static final Log log = Logs.get();
protected String origin;
protected String methods;
protected String headers;
protected String credentials;
public MyCrossOriginFilter() {
this("*", "GET, POST, PUT, DELETE, OPTIONS, PATCH", "Origin, Content-Type, Accept, Authorization, X-Requested-With, deviceType, deviceCode, deviceVersion, deviceInfo, platformVersion, platformType, token", "true");
}
public MyCrossOriginFilter(String origin, String methods, String headers, String credentials) {
this.origin = origin;
this.methods = methods;
this.headers = headers;
this.credentials = credentials;
}
public View match(ActionContext ac) {
log.info("1111111==================22222222222");
HttpServletResponse resp = ac.getResponse();
if (!Strings.isBlank(this.origin)) {
resp.setHeader("Access-Control-Allow-Origin", this.origin);
}
if (!Strings.isBlank(this.methods)) {
resp.setHeader("Access-Control-Allow-Methods", this.methods);
}
if (!Strings.isBlank(this.headers)) {
resp.setHeader("Access-Control-Allow-Headers", this.headers);
// resp.setHeader("Access-Control-Expose-Headers", this.headers);
}
if (!Strings.isBlank(this.credentials)) {
resp.setHeader("Access-Control-Allow-Credentials", this.credentials);
}
if ("OPTIONS".equals(ac.getRequest().getMethod())) {
if (log.isDebugEnabled()) {
log.debugf("Feedback -- [%s] [%s] [%s] [%s]", new Object[]{this.origin, this.methods, this.headers, this.credentials});
}
return new VoidView();
}
return null;
}
}