OGNL学习笔记
OGNL:
应用的场景:
标签中:
<s:property value="user.name">
配置文件中
<result type="redirect">/main.jsp?name=${name}</result>
调用值栈中对象的普通方法
<s:property value="user.get()">
调用Action中的静态方法 @
<s:property value="@cn.hhty.action.LoginAction@get()">
获取List集合:有序不重复
<s:property value="testList"/> 结果:[list1,list2,list3]
获取集合中的某一个元素
<s:property value="testList[0]">
(可以使用数组中的下标来获取List中的内容)
获取Set集合:无序可重复
获取Set集合
<s:property value="testSet"/> 结果:[set1,set2,set0]
获取Set中某一元素(由于Set无序,所有不能使用下标来取得)
获取Map集合
<s:property value="testMap"/>结果:[key1=value1,key2=value2]
获取Map中某一元素
<s:property value="testMap['key']">
获取大小
<s:property value="testMap.size">
返回map中所有的键:<s:property value="testMap.keys">
返回Map中所有的值:<s:property value="testMap.values">
获取List中所有的对象
<s:property value="listStudents">
利用投影获取List中对象的username属性值
<s:property value="listStudents.(username)">
利用投影获取List中第一个对象的username属性值
<s:property value="listStudents.(username)[0]">
利用投影获取List中成绩及格的对象
<s:property value="listStudents.(?#this.grade>=60).{username}[0]"/>
OGNL中#的使用:
#可以取出堆栈中上下文中存放的对象
<action name="test" name="username">
<input type="text" name="password">
Test1Action:
private String username;
private String password;
private Student student;
getter/setter
execute method just return success
Test2Action
private Student student;
execute method just return success
服务器跳转:
<action name="test1" name="code"><action name="test1" name="code"><action name="test1" class="com.test.test2Action"><result type="redirect">test2.jsp</result></action>