struts2.1访问静态方法需配置OGNL
如题,struts2.1 OGNL访问静态方法需要在struts.xml里边配置:
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
默认是false,可以在struts2-core-2.1.6.jar下org.apache.struts2里的default.properties里边查看到。
页面OGNL访问方式为:<s:property value="@类名@方法名"/>
---------
顺带:
访问Math类静态方法:<s:property value="@@方法名"/>如:<s:property value="@@max(2,3)"/>
--------------------
<body>
<ol>
<li>访问值栈中的action的普通属性: username = <s:property value="username"/> </li>
<li>访问值栈中对象的普通属性(get set方法):<s:property value="user.age"/> | <s:property value="user['age']"/> | <s:property value="user[\"age\"]"/> | wrong: <%--<s:property value="user[age]"/>--%></li>
<li>访问值栈中对象的普通属性(get set方法): <s:property value="cat.friend.name"/></li>
<li>访问值栈中对象的普通方法:<s:property value="password.length()"/></li>
<li>访问值栈中对象的普通方法:<s:property value="cat.miaomiao()" /></li>
<li>访问值栈中action的普通方法:<s:property value="m()" /></li>
<hr />
<li>访问静态方法:<s:property value="@com.bjsxt.struts2.ognl.S@s()"/></li>
<li>访问静态属性:<s:property value="@com.bjsxt.struts2.ognl.S@STR"/></li>
<li>访问Math类的静态方法:<s:property value="@@max(2,3)" /></li>
<hr />
<li>访问普通类的构造方法:<s:property value="new com.bjsxt.struts2.ognl.User(8)"/></li>
<hr />
<li>访问List:<s:property value="users"/></li>
<li>访问List中某个元素:<s:property value="users[1]"/></li>
<li>访问List中元素某个属性的集合:<s:property value="users.{age}"/></li>
<li>访问List中元素某个属性的集合中的特定值:<s:property value="users.{age}[0]"/> | <s:property value="users[0].age"/></li>
<li>访问Set:<s:property value="dogs"/></li>
<li>访问Set中某个元素:<s:property value="dogs[1]"/></li>
<li>访问Map:<s:property value="dogMap"/></li>
<li>访问Map中某个元素:<s:property value="dogMap.dog101"/> | <s:property value="dogMap['dog101']"/> | <s:property value="dogMap[\"dog101\"]"/></li>
<li>访问Map中所有的key:<s:property value="dogMap.keys"/></li>
<li>访问Map中所有的value:<s:property value="dogMap.values"/></li>
<li>访问容器的大小:<s:property value="dogMap.size()"/> | <s:property value="users.size"/> </li>
<hr />
<li>投影(过滤):<s:property value="users.{?#this.age==1}[0]"/></li>
<li>投影:<s:property value="users.{^#this.age>1}.{age}"/></li>
<li>投影:<s:property value="users.{$#this.age>1}.{age}"/></li>
<li>投影:<s:property value="users.{$#this.age>1}.{age} == null"/></li>
<hr />
<li>[]:<s:property value="[0].username"/></li>
</ol>
<s:debug></s:debug>
</body>
分享到:
相关推荐
主要介绍struts2.1 中的ognl中的表达式的用法
MYECLIPSE + STRUTS2 + SPRING4 + HIBERNATE4 + STRUCTS2S+OGNL + MYSQL_5.7.12
从官网checkout下来的源码,如果大家觉的区官网麻烦可以直接下载这个
基于 Struts2.1.8 包括Struts2的基本应用、文件上传、拦截器、输入校验、国际化、OGNL表达式、Struts2标签等内容。
一直以来都知道Struts2的OGNL支持在前台调用后台的静态方法,以前也用过,但用的比较少,今天自己重新开始了一个新的项目,在实现一个功能的时候用到了Struts2的在前台调用后台的静态方法,弄了半天没有出来结果,...
本资源适合刚接触Struts和Ognl的小伙伴交流学习,欢迎吐槽。
1、struts资源文件中文解决方法 1 2、开发struts2流程 1 3、创建拦截器: 2 4.标签中引用资源文件内容 3 5.创建资源文件 3 6.Action中访问servlet API 3 7.Action访问资源文件 3 8.资源文件_各国代码 4 9.将...
Struts2的OGNL表达式语言Object-Graph Navigation Language
Apache Struts Copyright 2000-2007 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
This class provides static methods for parsing and interpreting OGNL expressions
xwork-core-2.1.6.jar struts2-core-2.1.8.1.jar ognl-2.7.3.jar freemarker-2.3.15.jar commons-logging.jar commons-io-1.3.2.jar commons-fileupload-1.2.1.jar
struts2的ognl
Struts2的标签库及OGNL表达式语言
Struts2学习计划5---Struts2_OGNL(对象图导航语言)的学习
本案例提供ognl使用详解,测试通过,只需解压放入自己WEB项目中,执行struts_ognl包内java文件即可(未提供jia包,若需要可以联系留言发至邮箱),若测试不好可以联系本人提供指导. Struts 2默认的表达式语言是OGNL...
struts2.16+ognl2.61+xwork2.1源码 解压后就可以用了
有对struts2标签和OGNL的总结。
struts2 中 OGNL表达式的使用struts2 中 OGNL表达式的使用
1、概述在Struts2中,使用Ognl表达式作为字符串与对象之间转换的一种实现,通过Ognl表达式可以轻松做到String与Object之间的沟通 2、基本操
学习OGNL在Struts2中工作原理学习OGNL在Struts2中工作原理学习OGNL在Struts2中工作原理学习OGNL在Struts2中工作原理