设置Struts2 devMode = false后,/struts /webconsole.html仍在工作

时间:2015-06-17 06:23:19

标签: java struts2 appfuse

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

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

struts.propertiesstruts.devMode=false

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

4 个答案:

答案 0 :(得分:5)

devMode属性与webconsole无关,它只执行以下操作:

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

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

答案 1 :(得分:3)

只需在<struts>标记内写下以下行。

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

答案 2 :(得分:0)

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

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

通过检查加载的webconsole.html我发现它无法正常工作,即使您尝试通过一些JavaScript更改来修复它,如果struts是DebuggingInterceptor也不会接受来自此页面的任何数据不在devMod。

@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

答案 3 :(得分:0)

当我们将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>
相关问题