Struts 2 Reading Notes-Use of wildcards

Source: Internet
Author: User
  Configure  action  ,   struts. XML     
    
     ... /> The vast majority of 
      are the same. In this case, we can use the  struts 2 
      provided  wildcard ing mechanism to solve this problem. 
     

in .... /> , you can specify name use a pattern string (that is, use" * " to replace one or more arbitrary characters ), next, you can class , method attributes and ... /> in use {n } to represent the first few * represents a character.

1. When we go to action name If a wildcard is used in an attribute, you can use elements replace multiple logics Action .

1 <ActionName= "* Action"Class= "Com. App. Action. loginaction"Method= "{1 }">

A series of logical actions are defined above. . That is, as long as the user requests Url = * Action Mode, you can use this Action . For Method Attribute, which is: {1} . Indicates that the value of this expression is Name The first attribute in the attribute value * . For example URL Is Registaction . Call Registaction Class Regist Method.

2. class attributes can also be used {n } expression. That is, struts 2 A series of action Configure to a element. Equivalent to the element is configured with multiple logics action

1 <ActionName= "* Action"Class= "Com. App. Action. {1} action">

 

  The above Struts. xml Medium Class Attribute value used {N} Format expression. This expression indicates: If RUL Is Loginaction Request, the first of which is * Is Login , That is Action The processing class is Loginaction . Specifies the processing method as the default execute () method.

 Based on the above description: you can determine the followingStruts. xmlConfiguration

 
1 <ActiionName= "*_*"Method= "{1 }"Class= "Com. App. Actions. {2 }" >
    The aboveAction  The mode is  **_*  So all requests that match this mode can be  Action  Processing. If one  URL  Is  Regist_login.action  . Because it matches  *_*  Request, and the first  *  Is  Regist  , The second is Login  . It means to call  Com. App. Action. Login  Processing class  Regist  Method to process this request. 

 

Read Li Gang's lightweight Java EE Enterprise Application Practice (Third edition)-Struts 2 + spring 3 + hibernate Integrated Development
 

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.