Http://hi.baidu.com/kalada/blog/item/daaf0482e4b11499f703a617.html
1. Tag Value Method 1
Use <s: property value = ""/>
When the valuestack of an action contains the value of this attribute, you only need to directly 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 exists in the application.
You can use the following methods 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. Tag value method 2
Use % {} In any <s:/> label.
When the valuestack of an action contains the value of this attribute, you only need to directly 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 exists in the application.
<S: textfield name = "person. Name" value = "person. Name"/> // error. The person. Name is displayed in the Value Field.
<S: textfield name = "person. Name" value = "% {person. name}"/>
<S: textfield name = "person. Company. Name" value = "% {# company. name}"/>
<S: textfield name = "person. Company. Name" value = "% {# ATTR. Company. name}"/>
3. Obtain the attributes in the request, session, and application of the JSP page.
You can obtain the following information on the page:
<TD >$ {applicateionscope. Counter} </TD>
<TD >$ {sessionscope. Counter} </TD>
<TD >$ {requestscope. Counter} </TD>
Or use $ {property }$ {userbean. Username} directly }. 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 in the following ways:
Httpservletrequest r = servletactioncontext. getrequest ();
Httpservletresponse resp = servletactioncontext. getresponse ();
Struts2 also provides the following interfaces:
Servletcontextaware: Action implements this interface and can directly access servletcontext.
Servletrequestaware: Action implements this interface and can directly access httpservletrequest.
Servletresponseaware: Action implements this interface and can directly access httpservletresponse.