Because the form attribute in struts2 is also defined in action, struts2 puts the entire action in the request. The content distribution in the request processed by struts2 is as follows: Request Response Attrib1 Attrib2 Valuestack success Actioncontext Useraction response Property1 Property2 There is a valuestack in the request, which contains an actioncontext and action itself. The actioncontext contains the request, session, application, and other scopes displayed in the form of map. For example Request. getattribute ("A") = (MAP) actioncontext. getcontext (). Get ("request"). Get ("") // True
Session. getattribute ("B") = (MAP) actioncontext. getcontext (). Get ("session"). Get ("B ") // Or Session. getattribute ("B") = actioncontext. getcontext (). getsession (). Get ("B ") // Also true You can call servletactioncontext in the action to obtain the httpservletreqeust object and put it directly into the request. Then this attribute becomes the attrib1 and attrib2 above. (Servlet APIs are not officially recommended for use directly in action) You can also set the attribute in the action to the property1 and property2 above. On the page, both of the two can be obtained using the <s: property/> tag, but the acquisition method is different. property1 and 2 can be directly used. <S: property value = "property1"/> In this way However, if you use the same method to get attrib1, for example, <s: property value = "attrib1"/>, nothing will be obtained. How to obtain attrib1? How can I use <s: Property> to obtain attributes that directly exist in the request? Use the ognl expression <s: property value = "# request. attrib1"/>. |