Struts2 uses 16-value stack and ognl 1-Overview

Source: Internet
Author: User

 

The meaning of the value stack is as indicated by its name-the stack composed of objects. The full name of ognl is object graph navigational language (object graph Navigation language), which provides a unified way to access objects in the value stack. It is a powerful expression language (EL). With its simple and consistent expression syntax, it can access any attributes of an object and call methods of an object, traverse the structure of the entire object to convert the field type. It uses the same expression to access the attributes of an object.

The composition and order of objects in the value Stack are as follows:

1. Temporary object-during execution, the temporary object is created and placed in the value stack. For example, in an object container that is traversed by a JSP tag, the currently accessed value is a temporary object.

2. model object-if the model object is in use, it will be placed above the action in the value Stack

3. Action object -- the action being executed

4. named objects-these objects include # application, # session, # request, # ATTR and # parameters, and the corresponding servlet scope.

There are many methods to access the value stack. One of the most common methods is to use the tags provided by JSP, velocity, or freemarker. In addition, HTML tags are used to access the attributes of objects in the value stack; control tags are used with expressions (such as if, elseif, and iterator); data tags are used (set and push) to control the value stack itself.

When using the value stack, we do not need to care about the scope of the target object. If you want to use the attribute "name", you can directly query it from the value stack. Each element in the value stack will check whether the attribute is owned in order of arrangement. If yes, the corresponding value is returned and the query ends. If not, the next element will be accessed ...... Until the end of the value stack is reached. This function is very powerful, so we don't need to know where the value is. The value exists in action, model, or HTTP request. As long as this value exists, it will be returned.

But it also has a disadvantage. If the requested attribute is a common attribute (such as "ID") and you want to obtain the value of this attribute from a specific object (such as Action, at this time, the attribute value returned by the first qualified object in the value Stack may not be the expected result. The returned result is indeed the value of the "ID" attribute, but it may come from JSP tags, temporary objects, or model objects. At this time, we need to use ognl to enhance the value stack function. Osgl is not limited to accessing object attributes. If we know the depth of an action in the value stack, we can replace "ID" with "[2]. ID ".

In fact, ognl is a complete set of expression languages. In ognl, you can use ". (For example, use "person. address "instead of" getperson (). getaddress (), which also provides type conversion, method calling, set operation and generation, ing between sets, expression operations, and lambda expressions. The ognl website provides a complete set of guidelines

Http://www.ognl.org/2.6.9/documentation/html/?ageguide/index.html.

 

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.