- 什么是OGNL,OGNL原理
- 全称:Object Graphic Navigate Language
- 对象图导航语言
- Struts2默认使用OGNL作为表达式语言
- OGNL是一个早期开源的项目,可以具有以下功能:
- 获取,设置对象属性
- 调用对象方法
- 调用静态方法和属性
- 对集合进行过滤和投影
- 使用:
- <%@taglib uri="/struts-tags" prefix="s" %>
- 获取Action属性值
- name:<s:property value="name" /><br/>
- psw:<s:property value="psw"/><br/>
- name.length():<s:property value="name.length()"/><br/>
- request.name:<s:property value="#request.name" ></s:property><br/>
- request.abc:<s:property value="#request.abc" ></s:property><br/>
- session.abc:<s:property value="#session.abc" ></s:property><br/>
- application.abc:<s:property value="#application.abc" ></s:property><br/>
- birth:<s:property value="birth"/><br/>
- birth:<s:date name="birth"/><br/>
- birth:<s:date name="birth" format="yyyy-MM-dd"/><br/>
- set,age:<s:set var="age" value="20"></s:set><br/>
- #age:<s:property value="#age"/><br/>
- <s:push value="10000"></s:push>
- <s:push value="'abcdef'">
- <%-- 压入栈顶中,在</s:push>后移除。 --%>
- <s:debug></s:debug>
- </s:push>
- <s:if test='sex.equals("m")'>男</s:if>
- <s:elseif test='sex.equals("f")'>女</s:elseif>
- <s:else>not M not F</s:else>
- <br/>
- <table width="40%" style="font-size: 25px;" >
- <tr>
- <td>No</td><td>PNo</td><td>Name</td><td>Sex</td><td>Age</td>
- </tr>
- <s:iterator value="persons" var="p" status="sta">
- <tr>
- <%--
- <td><s:property value="#sta.index+1"/></td>
- <td><s:property value="#sta.count"/></td>
- <td><s:property value="#sta.first"/></td>
- <td><s:property value="#sta.even"/></td>
- --%>
- <td><s:property value="#sta.odd"/></td>
- <td><s:property value="#p.no"/></td>
- <td>${p.name }</td>
- <td><s:property value="#p.sex"/></td>
- <td><s:property value="#p.age"/></td>
- </tr>
- </s:iterator>
- </table>
- <br/>
- <table width="40%" style="font-size: 25px;">
- <tr>
- <td>No</td><td>Name</td><td>Sex</td><td>Age</td>
- </tr>
- <s:iterator value="persons">
- <tr>
- <td><s:property value="no"/></td>
- <td><s:property value="name"/></td>
- <td><s:property value="sex"/></td>
- <td><s:property value="age"/></td>
- </tr>
- </s:iterator>
- </table>
- <s:form action="form">
- <s:textfield label="姓名" name="name" labelposition="left"></s:textfield>
- <s:password label="密码" name="psw" showPassword="true"></s:password>
- <s:textarea label="介绍" name="name"></s:textarea>
- <s:checkbox label="是否同意" name="yes_no"></s:checkbox>
- <s:submit value="提交"></s:submit>
- <s:reset value="重置"></s:reset>
- </s:form>
OGNL
最新推荐文章于 2019-08-23 22:15:38 发布