解决xxx in a frame because it set X-Frame-Options to sameorigin 问题之配置X-Frame-Options头

配置http的响应头信息:属性名X-Frame-Options。
可以配置的参数有两个,选第二个参数就行了:
1.DENY:浏览器拒绝当前页面加载任何Frame页面。
2.SAMEORIGIN:页面只能加载入同源域名下的页面。
3.ALLOW-FROM uri:只能被嵌入到指定域名的框架中。

/**
 * 配置“X-Frame-Options头”
 */
@WebFilter(filterName = "FrameFilter", urlPatterns = "/*")
public class FrameTao implements Filter {

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        response.setHeader("x-frame-options", "SAMEORIGIN");
        chain.doFilter(request, response);
    }

    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

}

解决xxx in a frame because it set X-Frame-Options to sameorigin 问题之配置X-Frame-Options头_第1张图片

至此完美解决了!!!

你可能感兴趣的:(JAVA,HTML+CSS+JS)