OGNL expression, ognl

Source: Internet
Author: User

OGNL expression, ognl
The OGNL expression tag has three values:

1. It is an OGNL expression.

2. the string must be escaped from the OGNL expression.

1) when the OGNL expression is converted to string display, it must be enclosed by '(single quotation marks.

2) to convert the string to an OGNL expression, add % {string} to convert the string.

3. It can only be a string.

Tags: 1. Data tags

1. property -- display data

Value -- the content to be displayed. If the OGNL expression is used to display a string, ''is used.

Escape -- true/false: The default value is true. If it is set to false, the html effect tag is displayed.

Default value: Put the string instead of OGNL

<S: property value = "'

2. set -- set a new variable and assign values

Var -- new variable name

Scope -- scope page/request/session/application

Value -- variable value, OGNL expression, which must be enclosed in single quotes

<s:set var="ah" value="newsList" scope="request"></s:set><s:property value="#request.ah"/>

3. url -- generate a url

Var -- variable name

Value -- the URL address to be generated. The string can be escaped from OGNL. You must manually write the complete address.

Action -- the URL to be generated. The string can be escaped from OGNL to generate an absolute path. This is generally used

<s:url var="uu" action="News_getAll"></s:url><s:property value="#uu"/>

 

4. bean -- Implementation class of JavaBean

Name -- Java class to be instantiated

Var -- variable name

5. param -- generate Parameters

Name -- Tag name

Value -- OGNL expression, with single quotation marks

<S: bean name = "com. itnba. maya. domel. news "var =" bbb "> <s: param name =" biaoti "value =" 'This is the custom title' "> </s: param> </s: bean> <s: property value = "# bbb. biaoti "/>

<s:url var="uu" action="News_getAll">    <s:param name="ids" value="'k001'"></s:param></s:url><s:property value="#uu"/>

 

 

6. date -- format the output date
Name -- date value to be formatted --- OGNL expression
Format --- format the display format.

<S: date name = "date" format = "MM dd, yyyy" var = "mydate"/> <s: property value = "mydate"/>

Ii. control tags

1. if... else
Test -- table-based OGNL

2. iterator
Var
Value -- OGNL
Status: even, odd, first, last, index, count
Begin
End
Step

<s:iterator var="aa" value="newsList" status="st"><s:if test="#st.even"><div style="background-color:#666666;"></s:if><s:else><div></s:else><s:property value="#st.index+1"/>.<s:property value="#aa.biaoti"/></div></s:iterator>

 

3. append/merge/subset

Var -- New Object Name
<Param> child element

<s:set value="{'aa','bb','cc'}" var="aa"></s:set><s:set value="{'11','22','33'}" var="bb"></s:set><s:append var="all">    <s:param name="one" value="#aa"></s:param>    <s:param name="two" value="#bb"></s:param></s:append>

 

<s:set value="{'aa','bb','cc'}" var="aa"></s:set><s:set value="{'11','22','33'}" var="bb"></s:set><s:merge var="all">    <s:param name="one" value="#aa"></s:param>    <s:param name="two" value="#bb"></s:param></s:merge><s:iterator value="#all"  var="t"><s:property value="#t"/><br></s:iterator>

 


4. generater
Seperator -- Separator
Val -- separator string
Var -- names of arrays separated

<s:generator val="'a,b,c,d'" separator="," var="s"></s:generator><s:iterator value="#s" var="t"><s:property value="#t"/><br></s:iterator>


5. sorted
Source --- set
Comparator -- comparison object

<s:set value="{'aaaa','bb','ccc','dddd'}" var="arr"></s:set><s:bean name="com.itnba.maya.domel.Duibiqi" var="duibiqi"></s:bean><s:sort comparator="duibiqi" var="sss" source="#arr" >    <s:iterator var="str">        <s:property value="#str"/><br>    </s:iterator></s:sort><s:property value="#arr.size()"/>

You also need to create a class to implement the Comparator interface. Used for comparison

package com.itnba.maya.domel;import java.util.Comparator;public class Duibiqi implements Comparator<String>{     @Override    public int compare(String o1, String o2) {        if(o1.length() > o2.length()){            return -1;        }        else if(o1.length() == o2.length()){            return 0;        }        else{            return 1;        }    }}

 

 

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.