STRUTS2 Web. XML Configuration __web

Source: Internet
Author: User
Tags exception handling

One, Struts2 configuration file
STRUTS2 related configuration files are web.xml,struts.xml,struts.properties,
STRUTS-DEFAULT.XML,VELOCITY.PROPERTIES,STRUTS-DEFAULT.VM. Where Web.xml,struts.xml is required, other configuration files can be selected. Their functions in the Web app are as follows:
Web. Xml: Contains all of the necessary framework components for the website deployment descriptor.
Struts.xml: Configures the primary configuration file for Struts2 that contains result/view types, action mappings, interceptors, and so on.
Struts.properties: Configures the frame properties of the struts2.
Struts-default.xml: In the file in Struts-action-x.x.jar, the file is the default configuration that should be included in the Struts.xml.
Welocity.properties: The configuration file for the velocity has been rewritten.
STRUTS-DEFAULT.VM: The default configuration relative to velocity.

Second, STRUTS2 configuration elements
The Struts2 core configuration file is the default struts.xml.
When necessary, the default configuration file can contain other configuration files, and the struts file can be placed in the jar and automatically inserted into the application so that each module can contain its own configuration file and be automatically configured. In the Freemarker and velocity modules, the template can also be loaded from the classpath, so the entire module can be included as a simple jar file.
The Struts.xml configuration file can contain interceptor, action classes, and results.
Struts.xml configuration element Description:

1, Packages
Packages:packages the actions, results, results types, interceptors
And Interceptor-stacks are assembled into a logical unit, conceptually, packages is like an object that can be written from other sub-packages, and can have its own separate parts.
The Name property is a required element of the packages, which is referenced as a keyword behind the package, and the extends element is optional, which allows the package to extend one and more packages defined in front of it. Attention
The Struts.xml file is first and foremost processed, and all extended packages need to be defined before the expansion package.
The abstract element is optional and can declare a configuration file that does not contain actions.

2, Namespace
The namespace element subdivides the actions into logical modules, each namespace has its own
Prefix (prefix), namespace avoids name collisions between actions, which are namespaces-aware ("namespace aware") when the current prefix appears in the URI, so these namespace The prefix does not have to be embedded in a form or connection.
The default namespace is an empty string "", and if the action is not found in the specified configuration file, namespace is also searched. The Local/global policy allows an application to have a global action configuration outside the action "extends" element hierarchy. The default namespace can also not be declared in the package.
Namespace prefix can be registered as Java's declared security to ensure that authorized users can access Namespace resources.
Root namespace ("/") is also supported, and root is the namespace when requesting the context path directly.

[Personal Understanding: The use of namespace is like path in struts1.x, but it is in the package what path, and in action to declare the action name of it]

3. Include
The Include element allows the framework to apply "divide and conquer" to configure the file. by include
Each profile must have the same format as Struts.xml, and a large project can organize the program modules in such a way.
The Include element can also appear alternately with the package, and the framework loads the configuration file in order.

4. Interceptor Configuration
Interceptor allows an application to define execution code before and after the action method executes.
Interceptor is important in application development, and there are many use cases for interceptor, such as validation, property population, security, logging, and profiling.
Interceptor is defined as a Java class, interceptor can also be assembled into interceptor-stack, and they will be executed in the order defined.
Some default interceptor-stack are defined in struts-default.xml so that the framework works well.

5. Action
The action is the "unit of work" for the frame. Action can specify a interceptor-stack,
A sequence of return type and a sequence of exception handling, but only the name attribute is required.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.