You can also use the ${property name} expression in result to access properties in the action

Source: Internet
Author: User
Tags access properties

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




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.