Struts2 tag Value Method

Source: Internet
Author: User

Struts2 tag Value Method
1. when the value of a tag is <s: property value = ""/>, you only need to directly use the value of this attribute when the valueStack of an Action has the value of this attribute; when the valueStack of an Action does not have the value of this attribute, for example, when the value of this attribute is in the session or application range, you need to add # Or # attr .; example: assume that an Action contains the person member variable and the company attribute exists in the application. You can use the following method to set the value: <s: property value = "person. name "/> <s: property value =" # person. name "/> <s: property value =" company. name "/> // cannot be obtained, because company is not in the valueStack of action <s: property value =" # company. name "/> 2. method 2: Use % {} In any <s:/> tag to set the value. When the valueStack of an Action contains the value of this attribute, you only need to use the name of this attribute; when the valueStack of an Action does not have the value of this attribute, for example, when the value of this attribute is in the session or application range, you need to add # Or # attr .; example: assume that an Action contains the person member variable and the company attribute <s: textfield name = "person. name "value =" person. name "/> // error. The value is directly displayed as person. name <s: textfield name = "person. name "value =" % {person. name} "/> <s: textfield name =" person. company. name "value =" % {# company. n Ame} "/> <s: textfield name =" person. company. name "value =" % {# attr. company. name} "/> 3. you can obtain the attributes of the request, session, and application on the JSP page as follows: <td >$ {applicateionScope. counter} </td> <td >$ {sessionScope. counter} </td> <td >$ {requestScope. counter} </td> or directly use: $ {attribute }$ {userBean. username }. UserBean can be an object in a request or session. The content of the Action Code in struts2 is: ActionContext ctx = ActionContext. getContext (); ctx. getApplication. put ("counter", new Integer (5); ctx. getSession. put ("counter", new Integer (5); ctx. put ("counter", new Integer (5); ctx. put is to directly set the request value. You can also obtain the request using the following method: HttpServletRequest r = ServletActionContext. getRequest (); HttpServletResponse resp = ServletActionContext. getResponse (); struts2 also provides the following interface: ServletContextAware: Action to implement this interface, you can directly access ServletContext. ServletRequestAware: Action implements this interface and can directly access HttpServletRequest. ServletResponseAware: Action implements this interface and can directly access HttpServletResponse.

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.