Struts2 struts2-convention-plugin (Zero Configuration) Basics

Source: Internet
Author: User

Zero Configuration is not configured. Instead, the configuration is greatly reduced by means of conventions greater than the configuration. A large number of conventions are used to schedule page jumps. 1. How to Use Convention1. copy the struts-Convention-plugin-2.1.6.jar file to the WEB-INF/lib Path 2. for the Convention plug-in, it will automatically search for all java classes located under the action, actions, struts, and struts2 packages. The Convention plug-in will treat the following two java classes as actions: (1) all implemented com. opensymphony. java class of xwork2.Action interface (2) All java classes whose names end with Action 3. when ing the Action name, follow the following two rules: 1) if the Action class name contains the Action suffix, remove the Action Suffix of the Action class name. Otherwise, no processing is performed. 2) convert the code of the Action class name (the first letter of each word is written in uppercase and the other letters are written in lowercase) into a line (all letters are in lowercase and words are separated by lines in Chinese), for example: the name attribute of the Acion mapped by LoginAction is login, and the name attribute of the Action mapped by GetBooks is get-books, the name attribute of the Action mapped by AddEmployeeAction is the actiing between actiong and the Result Template under add-employee: URL Result File that cocould match Result Type/hello success/WEB-INF/content/hello. jsp Dispatcher/hello success/WEB-INF/content/hello-success.htm Dispatcher/hello success/WEB-INF/content/hello. f Tl FreeMarker/hello-world input/WEB-INF/content/hello-world-input.vm Velocity/test1/test2/hello error/WEB-INF/content/test/test2/hello-error.html Dispatcher such: the namespace mapped to the package of the following Action is as follows: com. fun. actions. loginAction ing to/com. fun. actions. myoffice. map CarInfoAction to/myofficecom. fun. struts. myoffice. entINfoAction ing to/myofiice 4. by default. Convention always locates physical resources under the WEB-INF/content path of the WEB application, and the Convention for locating resources is: actionRUL + resultCODE + suffix. When a logical view cannot find the corresponding resource, Convention automatically uses ActionURL + suffix as the physical view resource. For example, when actions. fore. LoginAction returns the success string, Convention takes precedence over using the WEB-INF under the login-success.jsp/content/fore directory as the view resource. If the file cannot be found, login. jsp can also be used as the corresponding resource. If the input string is returned, Convention will look up the WEB-INF chain Convention in the login-input.jsp5.Action/content/fore if you want an Action not to enter an attempt page after processing ends, but another Action chain. With the Convention plug-in, you only need to follow the following three conventions. 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 URL of the second Action is: firstActionURL + resultCODE, such as, the first Action is OneAction, there is a method returned as "two", then you have to ensure that WEB-INF/content/under no one. jsp or one-two.jsp for the second action it should be named OneTwoAction, and the corresponding url should be: "one-two.action" several important constants struts. convention. action. disableJarScanning --- whether to search Actionstruts from the package. convention. action. package -------- the Convention plug-in uses this constant to specify the package as the root package struts. convention. result. Path --- set the root path of the view resource for the Convention plug-in. The default value is/WEB-INF/contentstruts. convention. result. flatLayout-if it is false, you can try to put the directory corresponding to the Action, without putting it in the WEB-INF/content Note: 1) struts. convention. exclude. packges: Specifies which packages of java classes are not scanned. the java classes in these package structures are not automatically mapped to actions; 2) struts. convention. package. locators: the Convention plug-in uses the package specified by this constant as the root package for searching Action. For actions. fore. loginAction class, which should be mapped to/fore/login according to the Conventions. If this constant is set to fore, the Action will be mapped to/login3) struts. convention. action. packages: the Convention plug-in uses this constant to specify a package as the root package to search for Action classes. In addition to scanning the classes of the four packages of action, actions, struts, and struts2, the Convention plug-in also scans one or more packages specified by the constant, and tries to find the Action class from it. Note: struts. convention. package. locators and struts. convention. action. packages have subtle functions. Developers must be careful when using these two constants.

Related Article

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.