Struts2.0 configuration file (web.xml)

web.xml is the web application loads the important information about servlet configuration file, play initialization servlet, filter, etc. The role of web programs.
In general, all of the MVC framework for Web applications need to load a core controller, then what method to load the core of such a controller does, servlet or filter become a good choice, because they will with the opening of web services automatically loaded. For the Struts 2 framework, need to load FilterDispatcher, as long as the Web application is responsible for loading FilterDispatcher, FilterDispatcher will be loaded applications, Struts 2 framework.
Because Struts 2 will be the core controller designed to Filter, rather than a normal Servlet. Therefore, in order to allow Web application loading FilterDispacher, only need to configure the web.xml file can FilterDispatcher.
Configuration FilterDispatcher code snippet is as follows:

"! - Configure Struts 2 framework for the core of Filter ->
"! - Struts 2 Core Filter to configure the name of -"
<filter-name> struts </ filter-name>
"! - Struts 2 Core Filter to configure the implementation class -"
<filter-class> org.apache.struts2.dispatcher.FilterDispatcher </ filter-class>
"! - Configure Struts 2 framework of the Action Pack structure is loaded by default -"
<param-name> actionPackages </ param-name>
<param-value> org.apache.struts2.showcase.person </ param-value>
</ init-param>
"! - Configure Struts 2 framework for the configuration of the provider class -"
<param-name> configProviders </ param-name>
<param-value> lee.MyConfigurationProvider </ param-value>
</ init-param>
</ filter>
"! - Configure Filter blocked URL ->
"! - Configure Struts 2 core FilterDispatcher block all user requests -"
<filter-name> struts </ filter-name>
<url-pattern> / * </ url-pattern>
</ filter-mapping>
Three initialization parameters which have special meaning:
config: This parameter value is a comma (,) separated strings, each string is an XML configuration file. Struts 2 framework will automatically load the attribute specifies a series of configuration files.
actionPackages: The value of the parameter is also an English comma (,) separated strings, each string is a package of space, Struts 2 framework will scan the packages of space under the Action class.
configProviders: If you need to achieve their own ConfigurationProvider class, the user can provide one or more implements ConfigurationProvider interface class, and then these classes the class name set to the value of the property, a number of class names in English between the comma (, ) separated.
In addition, also here to configure Struts 2 constants, each <init-param> element to configure a Struts 2 constant, which <param-name> sub-element specifies the constant name, and the sub-elements <param-value> specified constant value.

As for the filter-mapping attribute filter (Filter) must be an attribute, used to filter the request path, where in general on the Set / * form of right to intercept all requests uri (filter), unless you have to do some special treatment.

At this point configuring struts2 core controller, and basically complete the struts2 configuration in the web.xml file.

Note that point: If the web container is J2EE1.3 (servlet2.3), due to not automatically load the struts tag library, so the need to manually load the web.xml file, struts tag library, the file name struts-tags.tld generally placed in WEB-INF Now, you can choose their own but if the web container is J2EE1.4 (servlet2.4), then the web container will automatically load the tag libraries, Struts 2 tag library definition file is included in the struts2-core-2.0 .6. jar file, in the struts2-core-2.0.6.jar file in META-INF path that contains a struts-tag.tld documents,
This file is the Struts 2 tag library definition file, Servlet 2.4 specification will automatically load the tag library file, which struts-tags.tld file contains loads of information pieces: is as follows:
"! - Custom tag library version of -"
<tlib-version> 2.2.3 </ tlib-version>
"! - JSP custom tag libraries required version of -"
<jsp-version> 1.2 </ jsp-version>
<short-name> s </ short-name>
"! - Definition of Struts 2 tag library URI, jsp file, the application uri ->
<uri> / struts-tags </ uri> ...
</ taglib>
The servlet2.3 manual configuration is as follows:
"! - Manually configure Struts 2 tag library -"
"! - Configure Struts 2 tag library URI jsp file, the application uri, similar to the name space -"
<taglib-uri> / s </ taglib-uri>
"! - Struts 2 tag library definition specifies the physical location of files -"
<taglib-location> / WEB-INF/struts-tags.tld </ taglib-location>
</ taglib>
Here is an example:

<? xml version = "1.0" encoding = "UTF-8"?>
<web-app version = "2.4" xmlns = "" xmlns: xsi = "" xsi : schemaLocation = "">
<display-name> struts2 </ display-name>

<filter-name> exportFilter </ filter-name>
<filter-class> org.displaytag.filter.ResponseOverrideFilter </ filter-class>
</ filter>

"! - Used to initialize the Spring container Listener ->
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ listener>

<filter-name> struts2 </ filter-name>
<filter-class> org.apache.struts2.dispatcher.FilterDispatcher </ filter-class>
</ filter>

<filter-name> struts2 </ filter-name>
<url-pattern> / * </ url-pattern>
</ filter-mapping>

<welcome-file> index.html </ welcome-file>
<welcome-file> index.htm </ welcome-file>
<welcome-file> index.jsp </ welcome-file>
<welcome-file> default.html </ welcome-file>
<welcome-file> default.htm </ welcome-file>
<welcome-file> default.jsp </ welcome-file>
</ welcome-file-list>

</ web-app>

分类:Java 时间:2010-04-19 人气:1702
blog comments powered by Disqus


iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.377 (s). 14 q(s)