gpt4 book ai didi

struts2 - 如何在 struts 2 中设置 X-frame-options header

转载 作者:行者123 更新时间:2023-12-01 14:19:30 26 4
gpt4 key购买 nike

我有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 的值(value)

浏览器给我这个错误 -

加载“http://localhost:8081/finance/uploadFile”时遇到多个具有冲突值(“ALLOWALL、DENY”)的“X-Frame-Options” header '.回退到“拒绝”。

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

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

最佳答案

从 Alireza Fattahi 的评论中得到了答案。

我也在使用 spring security 和 struts。 Spring Security 添加了 X-Frame-Options - 默认情况下拒绝。

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

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

<sec:http>标签

关于struts2 - 如何在 struts 2 中设置 X-frame-options header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39073874/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com