【问题标题】:/struts/webconsole.html is still working after setting Struts2 devMode=false/struts/webconsole.html 在设置 Struts2 devMode=false 后仍然有效
【发布时间】:2015-09-02 05:21:08
【问题描述】:

我在struts.xml中设置了如下配置参数:

<constant name="struts.devMode" value="false" />
<constant name="struts.configuration.xml.reload" value="true" />
<constant name="struts.i18n.reload" value="false" />

struts.properties:struts.devMode=false

webconsole.html 页面仍在加载中。如何解决这个问题?

【问题讨论】:

  • 您的问题解决了吗?
  • 从 struts2 的 2.3.31 或 2.5.5 开始,webconsole 仅在设置了 devMode 时可见:issues.apache.org/jira/browse/WW-4601

标签: java struts2 appfuse


【解决方案1】:

devMode 属性与webconsole 无关,它只做这些事情:

  • 启用后,Struts 2 将在每个请求上重新加载资源包(这意味着您可以更改 .properties 文件,保存它们,然后查看在下一个请求中反映的更改)。
  • 它还会在每次请求时重新加载您的 xml 配置文件 (struts.xml)、验证文件等。这对于测试或微调您的配置很有用,而无需每次都重新部署您的应用程序。
  • 第三,也许是不太广为人知的设置,因此会引起很多混乱:它将调试级别或通常可以忽略的问题提升为错误。例如:当您提交一个不能在动作'someUnknownField' 上设置的字段时,它通常会被忽略。但是,当您处于开发模式时,会抛出异常,告诉您提交了无效字段。这对于调试或测试大型表单非常有用,但如果您依赖请求中未在操作上设置但您直接在视图层中使用的参数也会造成混淆(警告:不好的做法,您应该始终验证来自网络的输入)。

我假设你来自here,我的建议是:你不应该 甚至在生产机器上部署这个组件。

【讨论】:

【解决方案2】:

只需在&lt;struts&gt; 标记内写入以下行。

<constant name="struts.action.excludePattern" value="/struts/webconsole.html" />

【讨论】:

    【解决方案3】:

    webconsole.htmldevMode参数设置为false也会显示webconsole.html,即使调试拦截器根本不在拦截器包中!

    显示 struts 2 webconsole.html 是因为 struts 将其作为静态资源加载。请看DefaultStaticContentLoader

    通过检查加载的webconsole.html,我发现它不起作用,即使您尝试通过一些JavaScript更改来修复它,如果struts不在devMod中,DebuggingInterceptor将不会接受来自此页面的任何数据.

    @RajeevRanjan 工作正常。只需添加:

    <constant name="struts.action.excludePattern" value="/struts/webconsole.html"/>
    

    如果您不想访问任何内容,则必须添加此拦截器使用的 css 和 js

    <constant name="struts.action.excludePattern" value="/struts/webconsole.css"/>
    <constant name="struts.action.excludePattern" value="/struts/webconsole.js"/>
    

    我认为这应该/可以解决,请参阅https://issues.apache.org/jira/browse/WW-4601

    【讨论】:

      【解决方案4】:

      当我们将 dev-mode 设置为 false 时,客户端无法通过 webconsole.html 注入任何东西。顺便说一句,这个 webconsole.html 页面仍然存在,所以我们可以通过在 web.xml 中设置 security-constraint 来隐藏它们,以避免访问这个文件

      <security-constraint>
        <web-resource-collection>
          <web-resource-name>OGNLconsole</web-resource-name>
          <url-pattern>*/struts/webconsole.*</url-pattern>
        </web-resource-collection>
      </security-constraint>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-24
        • 1970-01-01
        相关资源
        最近更新 更多