gitlab和jenkins+nexus搭建使用
阿新 • • 發佈:2020-12-09
1.後端跨域
@WebFilter("/*")
public class CrossDomainFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
log.info("初始化跨域過濾器");
}
@Override
public void doFilter(ServletRequest req,
ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) response;
// 允許所有的請求域名訪問我們的跨域資源,可以固定單個或者多個內容
httpResponse.setHeader("Access-Control-Allow-Origin", "*");//
// httpResponse.setHeader("Access-Control-Allow-Origin", "http://localhost:9090");// 允許所有的請求域名訪問我們的跨域資源,可以固定單個或者多個內容
httpResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PUT");// 允許何種請求方法訪問該跨域資源伺服器
httpResponse.setHeader("Access-Control-Max-Age", "3600");// 預檢請求的有效期,單位為秒。有效期內,不會重複傳送預檢請求
httpResponse.addHeader("Access-Control-Allow-Headers",
"Accept,authorization,Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With");// 允許所有的請求header訪問,可以自定義設定任意請求頭資訊 後期加上 authorization
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");// 是否允許使用者傳送、處理cookie
//如果額外設定自己的頭需要在這定義
httpResponse.setHeader("Access-Control-Expose-Headers", "Access-Token");
chain.doFilter(req, httpResponse);
}
@Override
public void destroy() {
}
}
2.前端跨域
在第三月考試用得car裡