JSP expression <%=%> : Outputs the computed result of a Java variable or expression to the client <%= date%> similar to <% out.print (date)%>
JSP script fragment <%%>: One or more Java program code nested in <%%>
<% if (age>=18) {%>
Adult
<%}else{%>
Minor
<%}%>
OGNL Object Graph navigation language, is an expression language, can arbitrarily access the object's properties or the method of invoking the object, can traverse the entire object's structure diagram, realizes the object property type conversion
The 1.OGNL context is actually a map object that holds multiple JavaBean objects, which have a context root object that can access its property values directly using the name of the latter directly calling its property name, otherwise prefixed with "#key"
2.STRUTS2 's tag libraries use ONGL expressions to access actioncontext key Data objects: <s:property value= ""/>
3.struts2 set Actioncontext to OGNL context and place the value stack as a OGNL root object into Actioncontext
4. Value stack: You can put the delete query object in the value stack, access the object in the value stack without "#", Struts2 the current Actioncontext instance to the top of the stack, so the attribute in the action in OGNL can also omit "#";
5. Call the Actioncontext put (Key,value) into the data, need to use # access;
Three symbols: #% $
1. #符号
To access non-root object properties:
#session. MSG expression is equivalent to Actioncontext.getcontext (). GetSession (). getattribute ("MSG")
#parameters. id[0] Function equivalent to request.getparameter ("id")
#request. UserName equivalent to Request.getattribute ("UserName")
#session. UserName equivalent to Session.getattribute ("UserName")
#application. UserName equivalent to Application.getattribute ("UserName")
For filtering and projecting collections: persons. {? #this. age>25},persons. {? #this. name== ' Pla1 '}. {Age} [0]
Used to construct map:#{' foo1 ': ' bar1 ', ' foo2 ': ' Bar2 '}
2.% symbol
When the attribute of the flag is a string type, the value of the OGNL expression is computed, similar to the eval in JS;
3.$ symbol
Referencing the OGNL expression in an internationalized resource file
Referencing OGNL expressions in the configuration file of the STRUTS2 framework
Summarize the use of OGNL
Access attribute; Access method;
Access static properties and methods: The format of the expression is the full name of the @[class (including the package path)]@[Method name | Value name]
@[email protected] (' foo%s ', ' Bar ') or @[email protected]_name
Access Construction Method: <s:property value= "New Struts.vo.Student (' Li Xiaohong ', ' Belle ', 3, +). Username"/>
Accessing an array (set cannot use subscript to fetch data because there is no order); List;map
Access collection, projection selection (? ^ $)
Use the selection to get the username of the first object in the list: <s:property value= "Stus. {? #this. grade>=60}. {username} [0] "/><br>
Use the selection to get the username of the list of successful objects: <s:property value= "Stus. {? #this. grade>=60}. {username} "/><br>
Use the selection to get the Username:<s:property value= "Stus of the first object in the list. {^ #this. grade>=60}. {username} "/><br>
Use the selection to get the last object in list username: <s:property value= "Stus. {$ #this. grade>=60}. {username} "/><br>
Pseudo property of a collection: references some special properties of the collection, but these properties are not javabean patterns, such as size (), length (), which are pseudo-properties
Collection:size,isempty; List:iterator; Map:keys,values; Set:iterator; Iterator:next,hasnext;
Using lambda: [...] Expression calculation factorial: <s:property value= "#f =: [#this ==1?1: #this * #f (#this-1)], #f (4)"/><br>
JSP expression language