[Migration file] struts2 labels

Source: Internet
Author: User

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"/>.

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.