How to understand the action receiving parameters of struts2
This article will explain in detail how to understand the action receiving parameters of struts2. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Only receive parameter values (non-object)
If the parameters in Action are simply passed by the foreground,
For example, in Form
The method received in the background only needs to have setUserName ();, because it is a simple assignment.
Background object receive parameters
Format of the request: testAction? User.userName=admin
Then the object user is defined in Action:
Private User user = new User ()
At this point, there must be a getUser (); method, otherwise struts cannot find the corresponding object through reflection. As a result, you cannot assign values to specific properties in the object.
What distinguishes Action from java's getter and setter: the treatment of Boolean types.
Java:
Boolean isFlag = false;set method: public void setFlag (boolean isFlag) {this.isFlag = isFlag;} get method: public boolean isFlag () {return isFlag;}
Struts:
Boolean isFlag = false;set method: public void setIsFlag (boolean isFlag) {this.isFlag = isFlag;} get method: public boolean getIsFlag () {return isFlag;}
Reflection must be done as described above, which is the reflection rule set by struts itself.
On how to understand the action reception parameters of struts2 is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.