STRUTS2 0 Configuration (annotations) Access path

Source: Internet
Author: User
Tags constant

1. Packages that need to be imported

Struts2-convention-plugin-2.3.14.jar

Asm-3.3.jar

Asm-commons-3.3.jar

Asm-tree-3.3.jar

2. Rules for path access

Struts2-convention-plugin-*jar package, this package will default to retrieve the package name contains Struts,struts2,action,actions package, It then handles these classes that implement the action interface and the class name ends with action as action. Do not <init-param><param-name>actionpackages in the filter in Web. Xml ... Configuration is also possible.

Mapping Rules:

For classes that end in action, remove the action, take the remainder, convert all letters to lowercase, and if you have a camel-like notation, use the "-" connector to connect different words, which is the default way for this plugin. After the final conversion is the request address, see an example below:

(1)com.han.action.OrderAction This class according to the above rules, the result path is/order.action, access to the URL is: http://localhost:8080/ Project Name/order.action

(2) If your package name is in the back of the struts,sturts2,action,action2 and there are other words, then the next part is the default namespace, such as:

Com.han.action.other.OrderAction, the request path is:/other/order.action

(3) We also often use the hump naming method, and its default parsing rule is to use "-" connectors to connect different words, such as:

Com.han.action.UserOrderAction This request path is:/user-order.action

(4) If you have more than one keyword in your package name, it will be parsed in the order I wrote above, such as:

Com.han.struts.action.OrderAction, which contains struts and action while the default struts has a higher priority then the action is treated as a normal character (the default is the namespace).

So the request address is:/action/order.action;

And if it is: com.han.action.struts.OrderAction (because struts has a high priority) The end result is:/order.action

3. Modify the keywords that are retrieved by default

So what if we don't want to follow its default keywords to retrieve it? There is a way to modify the keyword that it retrieves by Struts.xml's constant configuration:

<constant name= "struts.convention.package.locators" value= "Han"/>

So let it default to the package name contains Han to determine the action

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.