Struts2 Study Notes
Note 6: struts. xml introduces multiple configuration files for dynamic method calls and parameter acquisition
(1 ),Introduce multiple struts configuration files
<Include file = "struts_user.xml"/>
<Include file = "struts_person.xml"/>
(2 ),Dynamic method call
2-1: The URL specifies the method name for access:
For example:Useraction! Userinfo. Action, indicating to call the userinfo method of useraction.
2-2: Configure constants for dynamic method calls
<Constant name = "struts. Enable. dynamicmethodinvocation" value = "true"/>
2-3: Access with wildcards
<Action name = "User _ *" class = "com. Controller. useraction" method = "{1}">
<Result>/index. jsp </result>
</Action>
IfUseractionThere are two methods: A and B.
This can be written as follows during the call:User_a.action, user_ B .action.
(3 ),Parameter acquisition: using attributes or object reflection
3-1: Add parameter fields in the action class
For example, public class useraction{
Private string name;
Public void setname (string name) {// This method is required
This. Name = Name;
}
// Other methods ....................
}
Note: The field name is the same as the name after set.
This parameter acquisition is not differentiated by the get/POST method. In essence, it is obtained by calling the getparameter method of httprequest.
3-2: Object Data Type (composite type) Reflection receiving Parameter
Public class useraction{
Private person;
Public void setperson (string person) {// This method is required
This.Person=Person;
}
Public String saveuser (){
Return "success ";
}
}
The form field can be person. ID, person. Name;
El expression for receiving JSP pages: Id =$ {person. ID}, name =$ {person. name}