Web. xml is an important configuration file for loading servlet Information in web applications. It initializes web programs such as servlet and filter.
Generally, all MVC frameworks require Web applications to load a core controller. Then, how can we load such a core controller? servlet or filter has become a good choice,
Because they will automatically load as web services are enabled. For the Struts 2 framework, FilterDispatcher needs to be loaded,
As long as the Web application is responsible for loading FilterDispatcher, FilterDispatcher will load the Struts 2 Framework of the application.
Because Struts 2 designs the core controller as a Filter instead of a common Servlet. Therefore, to load FilterDispacher to a Web application, you only need to configure FilterDispatcher in the web. xml file.
Configure struts in web. xml. For versions earlier than version 2.1.3, use org. apache. struts2.dispatcher. FilterDispatcher,
Later versions, configure org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter.
Struts2
Org. apache. struts2.dispatcher. FilterDispatcher
Config
Struts-default.xml, struts-plugin.xml,/WEB-INF/struts. xml
ActionPackages
Org. apache. struts2.showcase. person
ConfigProviders
Lee. MyConfigurationProvider
Truts. enable. DynamicMethodInvocation
False
Struts. devMode
False
Struts. objectFactory
Spring
Struts2
/*
Three initialization parameters have special meanings:
Config: the value of this parameter is a string separated by commas (,). Each string is the location of an XML configuration file. The Struts 2 Framework automatically loads the series configuration files specified by this attribute.
ActionPackages: the value of this parameter is also a string separated by commas (,). Each string is a package space. The Struts 2 Framework will scan the Action classes in these package spaces.
ConfigProviders: If you need to implement your own ConfigurationProvider class, you can provide one or more classes that implement the ConfigurationProvider interface,
Set the class names of these classes to the value of this attribute. Multiple class names are separated by commas.
In addition, you can also configure the Struts 2 constant here, each Element to configure a Struts 2 constant, where The sub-element specifies the constant name,
While The child element specifies the constant value.
The filter-mapping attribute is a required attribute of the Filter. It is used to filter the Request Path. It is generally set,
Intercept (filter) All request Uris unless you have to perform some special processing.
After configuring the core controller of struts2, the configuration of struts2 in the web. xml file is basically completed.
Note: If the web container is J2EE1.3 (servlet2.3), because the struts tag library is not automatically loaded, you need to manually load the struts tag library in the web. xml file,
File Name struts-tags.tld, usually placed under the WEB-INF, you can specify your own, but if the web container is J2EE1.4 (servlet2.4), then the web Container will automatically load the tag library,
Struts 2's label library definition file is included in the struts2-core-2.0.6.jar file, contains a struts2-core-2.0.6.jar file under the META-INF path of the struts-tag.tld file,
This file is the Struts 2 label library definition file, Servlet 2.4 specification will automatically load the label library file, where the struts-tags.tld file contains the piece of loading information:
2.2.3
1.2
S
/Struts-tags ...
The manual configuration of servlet2.3 is as follows:
/S
/WEB-INF/struts-tags.tld