问答详情
源自:5-11 简单请求和非简单请求2

没办法OPTIONS缓存


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缓存

提问者:叶梓欣 2018-03-15 18:31

个回答

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

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