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.