STRUTS2 uses 3--Struts2 configuration 1--web.xml, struts.xml configuration __web

Source: Internet
Author: User

Configure the Web.xml to configure the STRUTS2 filter, for example:

<filter>

<filter-name>struts2</filter-name>

<filter-class>

Org.apache.struts2.dispatcher.FilterDispatcher

</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

Struts.xml Main configuration file:

In Web applications we use deployment descriptors to initialize resources such as servlet, filter, listener, and so on, and this deployment descriptor is the well-known web.xml. Similarly, the framework uses a configuration file to initialize its own resources, which mainly include:
1. Interceptor (Interceptor): Pretreatment and post-processing of requests;
2. Action Classes: Responsible for invoking the business logic and data access layer;
3. Results: Responsible for returning views, such as JSP pages, and so on;

Bean Label Configuration

STRUTS2 is an extensible framework in which the core components of the framework are configurable and can be assembled by Struts2 their own dependency injection containers. Developers can write their own components to extend the framework functionality, and then configure the components with Bean elements.
The Struts-default.xml file defines the configurable components in the STRUTS2 framework.

Bean element Properties:

Property name

Whether you must

Descriptive information

Class

Is

Class name of the Bean

Type

Whether

The primary interface for the bean implementation

Name

Whether

The name of the bean, in a bean with the same type attribute, that must be unique

Scope

Whether

The scope of the bean is one of the Default,singleton,request,session,thread

Static

Whether

Whether to inject a static method and not true if Type,static is specified

Optional

Whether

Whether the bean is optional

Package Label configuration:

<package./> tags are used to organize the configuration of common information that needs to be shared--such as interceptor stacks or URL namespaces. It usually consists of the configuration of the action, but it can also include any type of configuration information. It can also be used to organize functions that manage their own independence--they can also be further split into different configuration files.

The packages in STRUTS2 are similar to Java packages, providing a way to organize action, result, interceptor, and interceptor stacks into a single logical unit, simplifying maintenance for you and improving reusability.
In the Struts.xml file, the settings associated with the Web application are defined in the package, and each package contains the action, result, interceptor, and interceptor stack that will be used.

Property name

Whether you must

Descriptive information

Name

Is

Unique identification of package, no name allowed

Extends

Whether

The name of the package inherited by the current package, all configuration information in the inherited package (including the configuration of the action) can be used under the new namespace, in the new package.

Namespace

Whether

namespaces provide mappings from URLs to package. In other words, if two different package, whose namespaces are "Package1" and "Package2" respectively, then the URL is almost "/mywebapp/package1/my.action" and

"/mywebapp/package2/my.action" in such a form.

Abstract

Whether

Declares that the package is abstract, and if the value of this property is "true", then the package is simply a combination of configuration information and cannot be accessed by package's name to access the configured action.

include tag configuration:

<include .../> is a child label for the <struts> tag, which can import other profiles into the module to achieve Struts2 modularity. Its "file" attribute defines the name of the file to import-the same structure as "struts.xml". In large project development, the project can be decomposed into several small modules, each module independently developed and managed. We can provide a configuration file for each module, configure it, and then use the include

in Struts.xml.

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.