A brief understanding of OGNL expressions introduced in Struts2

  1. The full name of OGNL is Object-Graph Navigation Language. It is a powerful expression language and a third-party open source project, which appeared earlier than EL expressions.

    It has nothing to do with Struts2. The Struts framework uses OGNL to calculate expressions.

    Struts2 uses simple and consistent expression grammar to access arbitrary attributes of objects and call object methods, as well as traverse the structure diagram of the entire object and realize the conversion of field types .

  2. OGNL operation attribute and method (example)
    tag introduction: <%@ taglib uri="/struts-tags" prefix="s" %>
    Static method authorization:
    attribute: <s:property value="@java.lang.Math@ PI"/>
    Method: <s:property value="@java.lang.Math@random() * 101"/>

  3. Features
    ① Supports object method calls, such as object.functionName()
    ② Supports constant access and static method calls of classes , the example of point 2 above
    ③ Supports direct creation of objects and manipulation of collection objects

Guess you like

Origin blog.csdn.net/qq_44965393/article/details/111932927