Java EE Development of various resources download list, the history of the most IT resources, personal collection summary.
Summarize:
(1) For a property in an action, you can set the value in two ways: the first is to assign a value directly in the action, and the second is to inject the value into the action's property in the Struts2 configuration file. Such as:
<action name= "Setter" class= "edu.action.AttributeAction" method= "attribute" >
<param name= "UserName" >zhangsan user</param>
<result name= "Showparam" >/page/showParam.jsp?userName=${userName}</result>
</action>
Before calling the action's attribute () method, Struts2 looks for the call to the Setusername () method, which assigns a value to the member variable of the action instead of looking for the Username property.
(2) In result you can also use the ${property name} expression to access the property in the action, and the property name in the expression corresponds to the property in the action, Note : This cannot be written as ${requestscope. Property name}
<result name= "Showparam" >/page/showParam.jsp?userName=${userName}</result>
(3) Struts when the request is forwarded to the URL of <result>, the property value of the Getter method (which is not based on the member variable Value ) is saved in the Requestscope scope, if the <result> URL with parameters and is forwarded to handle the client's request, the JSP can be accessed by ${param. Property name} or ${requestscope. Property name}.
(4) Assigning a value to an action's property in a configuration file using a dependency injection method, which is assigned before the method () is called.
Attributeaction.java
showparam.jsp
Struts.xml
Browser input: Http://localhost:8080/Struts2_02/attribute/setter