Struts2 learning: Configuring wildcard ing

Source: Internet
Author: User

The larger the application, the more action mappings there are. By using wildcards, We can bind some similar mappings together and use a more general mapping representation, the use of this wildcard is also mentioned in the previous chapter on action configuration. Here we will talk about it systematically.

There is a configured action ing as follows:

<Action

Name = "/edit *"

Class = "org. Apache. Struts. webapp. example. Edit {1} action">

<Result name = "failure" Path = "/mainmenu. jsp"/>

<Result Path = "/{1}. jsp"/>

</Action>

This action mapping can be used to match all action names starting with/edit, such as/editsubstration and editregistration, but/editsubscription/Add will not be matched. The content matched by the wildcard will be replaced with the action mapping and result attributes to replace {1 }. For example, if the/editsubpipeline matches, the path attribute of one of the results will be considered as subpipeline. jsp by the framework.

It should be noted that if the URL of a request matches multiple action mappings, select the last execution, that is, perform matching search in the order from the back to the back, one exception is that exact match takes precedence. If there is an action mapping that does not use wildcards or URLs for matching, the exact match takes precedence, equivalent to the matching principle in servlet.

The following describes some special characters in a wildcard:

*: It can match 0 or multiple arbitrary characters, but does not include the forward slash "/";

**: It can match zero or multiple arbitrary characters, including the forward slash ''/".

/: Backslash, escape character.

Because * does not match the forward slash, the Front/editsub/Add will not be matched.

In action mapping, the value matched by the wildcard can be accessed with the symbol {n}, where n is a number between 1 and 9, it is used to represent the value on which the nth value is matched. The popular point is the content indicated by the nth * number. For example, the wildcard expression is/edit */Add */confirm *, it matches/editorder/additem/confirmresult, so {1} indicates order, {2} indicates item, {3} indicates result, and so on.

 

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.