没办法OPTIONS缓存

来源:5-11 简单请求和非简单请求2

叶梓欣

2018-03-15 18:31


package com.imooc;


import java.io.IOException;


import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServletResponse;


import org.springframework.boot.autoconfigure.web.ResourceProperties.Chain;


public class CrosFilter implements Filter {


@Override

public void destroy() {

// TODO Auto-generated method stub


}


@Override

public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)

throws IOException, ServletException {

// TODO Auto-generated method stub

HttpServletResponse res = (HttpServletResponse)arg1;

res.addHeader("Access-Control-Allow-Origin", "*");

res.addHeader("Access-Control-Allow-Methods", "*");

// res.addHeader("Access-Control-Allow-Headers", "Content-Type");

// res.addHeader("Access-Control-Max-Age", "3600");//单位是秒

arg2.doFilter(arg0,arg1);

}


@Override

public void init(FilterConfig arg0) throws ServletException {

// TODO Auto-generated method stub


}


}

得不到OPTIONS缓存

写回答 关注

1回答

  • 叶梓欣
    2018-03-15 18:40:05

    唉,手欠把disable cache打上勾了……已解决

    空想白夜

    同样的问题,前几章的视频是有打勾的¬_¬

    2019-01-18 20:45:57

    共 1 条回复 >

ajax跨域完全讲解

完全讲解Ajax跨域产生的原因和解决思路,掌握跨域的各种解决方案

62553 学习 · 90 问题

查看课程

相似问题