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