Struts2 convention, struts2

Source: Internet
Author: User

Struts2 convention, struts2
Zookeeper

Struts2 introduces the Convention (Convention) Plug-in to support zero configuration. Conventions are better than configurations.

I. Agreed Action1. install the Convention plug-in

Copy the struts-convention-plugin-2.2.1.jar file under the Struts2 project to the WEB-INF \ lib path of the Struts2 application to search for all Java classes under the action, actions, struts, struts2 package,

The Convention plugin treats the following two Java classes as actions:

(1) All Java classes that implement com. opensymphony. xwork2.Action.

(2) All Java classes whose names end with actions

The Convention plug-in of Struts2 allows the following three constants to be set:

(1) struts. convention. exclude. packages: Specifies which packages are not scanned for Java classes

(2) struts. convention. package. locators: the Convention plug-in uses the package specified by this constant as the root package for Action search. For the actions. lee. LoginAction class, it is originally mapped to/lee/login according to the Conventions. If this constant is set to lee, the Action will be mapped to/login.

(3) struts. convention. action. packages: the Convention plug-in uses the specified constant package as the root package to search for Action. Searches for all Java classes in the action, actions, struts, struts2 packages, and the packages defined by this constant.

URL ing of Action

(1) If the Action class name contains the Action suffix, remove the Action Suffix of the Action class name. Otherwise, no processing is performed. For example, org. actions. LoginAction is mapped to/login. action.

(2) Translate the hump of Action class name into a hyphen, such as org. actions. books. GetBooks ing to/books/get-books.action

Ii. Agreed Result

After processing a user request, Action returns a string as the logical view. This logical view must be mapped to the actual physical view to make sense. By default, Convention also provides conventions for ing between logical and physical views.

Are some ing instances supported by Convention:

Iii. Action chain conventions

If you want an Action to form an Action chain instead of entering the view page after processing, you only need to follow the following three conventions through the Convention plug-in:

(1) The logical view string returned by the first Action does not have the corresponding view Resource

(2) The second Action and the first Action are in the same package.

(3) The second Action ing URL is: firstactionName + resultcode

Iv. Automatic Reload ing

Configure two constants of Struts2 (web. xml, struts. xml, and struts. properties ):

<! -- Configure the Struts2 application to be in development mode -->

<Constant name = "struts. devMode" value = "true"/>

<! -- Configure the Convention plug-in to automatically reload the ing -->

<Constant name = "struts. convention. classes. reload" value = "true"/>

5. Annotation related to the Convention plug-in

The Convention plug-in of Struts2 focuses on the management of Action and Result ing. In addition to managing Action and Result, the configuration file of Struts2 also needs to manage information such as interceptor and exception handling, convention uses Annotation to manage these configurations. In addition, Convention allows Annotation to manage the configuration of Action and Result to overwrite the Convention.

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.