Struts2 learning notes-dynamic method call and parameter acquisition

Source: Internet
Author: User
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}



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.