如何在struts 2中设置X-frame-options标头

时间:2016-08-22 07:44:21

标签: struts2

我有struts 2的应用程序

对于上传文件,我使用iframe作为表单提交的目标。

它给了我错误 -

Load denied by X-Frame-Options: http://localhost:8081/finance/uploadFile does not permit framing.

我在请求中检查了X-Frame-Options,它是 DENY

为了允许X-Frame-Options,我添加了一个这样的拦截器 -

@Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
    final ActionContext ac = actionInvocation.getInvocationContext();
    HttpServletResponse response = (HttpServletResponse)ac.get(StrutsStatics.HTTP_RESPONSE);
    response.setHeader("X-Frame-Options", "ALLOWALL");
    return actionInvocation.invoke();
    }

但我仍然看到X-Frame-Options ALLOWALL,DENY

的价值

浏览器给我这个错误 -

多个' X-Frame-Options'加载' http://localhost:8081/finance/uploadFile'时遇到有冲突值(' ALLOWALL,DENY')的标题。回到DENY'

我不明白我只是设置请求标头ALLOWALL,但它从哪里得到DENY。

有人可以帮助您正确地做到这一点。

1 个答案:

答案 0 :(得分:0)

Alireza Fattahi的评论得到了答案。

我也使用弹簧安全性和struts。而弹簧安全性正在默认添加X-Frame-Options - DENY。

我在spring安全配置中进行了以下更改以更改默认行为。

<sec:headers>
    <sec:frame-options policy="SAMEORIGIN"/>
</sec:headers>
<sec:http>代码

中的