[Struts2]配置 web.xml文件
2011-10-29 19:44
274 查看
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 theweb.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.
actionPackages - a comma-delimited list of Java packages to scan for Actions.
configProviders - a comma-delimited list of Java classes that implement theConfigurationProvider interface that should be used for building the Configuration.(Struts2使用StrutsXmlConfigurationProvider从xml文档中加载它的配置。configProviders参数让你可以指定自己的ConfigurationProvider接口实现。
* - any other parameters are treated as framework constants.
FilterDispatcher Example (web.xml)
If, for some reason, a taglib configuration is needed within web.xml, extract the TLD file from thestruts-core.jarMETA-INF
folder, and add a taglib element to theweb.xml.
http://struts.apache.org/2.0.8/docs/webxml.html
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.(如果没有设置这个参数,默认加载struts-default.xml,struts-plugin.xml,struts.xml)actionPackages - a comma-delimited list of Java packages to scan for Actions.
configProviders - a comma-delimited list of Java classes that implement theConfigurationProvider interface that should be used for building the Configuration.(Struts2使用StrutsXmlConfigurationProvider从xml文档中加载它的配置。configProviders参数让你可以指定自己的ConfigurationProvider接口实现。
* - any other parameters are treated as framework constants.
Simple Example
Configuring web.xml for the framework is a matter of adding a filter and filter-mapping.FilterDispatcher Example (web.xml)
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>com.mycompany.myapp.actions</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- ... --> </web-app>
Taglib Example
Typically, configuring a taglib is neither required nor recommended. The taglib is included instruts-core.jar, and the container will discover it automatically.If, for some reason, a taglib configuration is needed within web.xml, extract the TLD file from thestruts-core.jarMETA-INF
folder, and add a taglib element to theweb.xml.
<!-- ... --> </welcome-file-list> <taglib> <taglib-uri>/s</taglib-uri> <taglib-location>/WEB-INF/struts-tags.tld</taglib-location> </taglib> </web-app>
http://struts.apache.org/2.0.8/docs/webxml.html
相关文章推荐
- struts1,struts2在web.xml里的配置文件
- Spring和Struts2配置文件不在默认路径下的web.xml配置方法
- Struts2 web.xml文件配置
- 配置安装Struts2 web.xml文件
- Struts2的简单配置文件web.xml
- 配置Struts2 web.xml文件
- Struts2的配置文件——web.xml
- SSH项目web.xml文件的常用配置【struts2的过滤器、spring监听器、解决Hibernate延迟加载问题的过滤器、解决中文乱码的过滤器】
- Struts2的配置文件——web.xml
- Struts2中的配置文件--web.xml文件
- Struts2的配置文件——web.xml
- struts2的web.xml文件配置
- 2.struts2配置文件Web.XML与Struts.XML模板详细说明
- Struts2配置文件复用代码【web.xml、struts.xml、常量配置】
- Struts2配置文件复用代码【web.xml、struts.xml、常量配置】
- Struts2项目中的web.xml文件的配置问题入门
- Struts2的配置文件——web.xml
- struts2 的web.xml 配置文件报错org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
- Struts2的配置文件——web.xml
- struts2配置web.xml文件