Struts2 Web.XML

The web.xml web application descriptor(描述) file represents the core of the Java web application, so it is appropriate that it is also part of the core of the Struts framework. In the web.xml file, Struts defines its FilterDispatcher(控制器), the Servlet Filter class that initializes(初始化) the Struts framework and handles all requests(处理所有的请求). This filter can contain initialization parameters that affect what, if any,additional(额外增加的) configuration files are loaded and how the framework should behave.

In addition to(除..之外) the FilterDispatcher, Struts also provides an ActionContextCleanUp class that handles special cleanup tasks(处理特殊的清理工作) when other filters, such as those used by Sitemesh, need access to an initialized Struts framework.

Key Initialization Parameters

  • config - a comma-delimited list(逗号分割的列表) of XML configuration files to load.

  • actionPackages - a comma-delimited list of Java packages to scan(扫描) for Actions.

  • configProviders - a comma-delimited list of Java classes that implement the ConfigurationProvider interface that should be used for building the Configuration.

  • loggerFactory - The class name of the LoggerFactory implementation.

  • * - any other parameters are treated as framework constants.

Why the Filter is mapped with /* and how to configure explicit exclusions(明确排除) (since 2.1.7)
In the example above we've mapped the Struts 2 dispatcher to /*, so Struts 2 has a crack(入口,裂缝) at all incoming(传入,进来) requests. This is because Struts 2 serves static content from its jar files, including Dojo JavaScript files (if using S2.0, or the Dojoplugin(插件) in S2.1+) and FreeMarker templates(模板) for the Struts 2 tags that produce HTML.

If we change the filter mapping to something else(别的东西), for example /*.html, we must take this in to account and extract the(提取) content that would normally be served from the Struts 2 jar files, or some other solution.

Since Struts 2.1.7, you are able to provide a comma seperated(分离) list of patterns for which when matching against the
request URL the Filter will just pass by. This is done
via(通过) the configuration option struts.action.excludePattern, for example in your struts.xml

<struts>
    <constant name="struts.action.excludePattern" value=".*unfiltered.*,.*\\.nofilter"/>
    ...

</struts>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值