OGNL:

什么是OGNL 

Object Graph Navigation Language

开源项目,取代页面中Java脚本,简化数据访问

和EL同属于表达式语言,但功能更为强大 

OGNL在Struts 2中的作用

表达式语言

将表单或Struts 2标签与特定的Java数据绑定起来,用来将数据移入、移出框架 

类型转换 

数据进入和流出框架,在页面数据的字符串类型和Java数据类型之间进行转换

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>OGNL表达式语言学习</title>
</head>
<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="[0].username"/></li> </ol> <s:debug></s:debug>
</body>
</html>
非值栈对象 	访问方式	等价访问方式
application #application.username
#application['username'] application.getAttribute("username")
session #session.username
#session['username'] session.getAttribute("userName")
request #request.username #request['username'] request.getAttribute("username")
parameters #parameters.username
#parameters['username'] request.getParameter("username")
attr #attr.username
#attr['username'] 按pageContext–>request–>session –>application顺序查找

最新文章

  1. import sun.net.www.MimeTable报错
  2. CSS系列:CSS文字样式
  3. GetEnumerator();yield
  4. attr和prop区别
  5. DES带IV向量加密解密工具
  6. OSGI入门笔记
  7. android 入门-Service实时向Activity通过BroadcastReceiver传递数据
  8. TC SRM 584 DIV 2
  9. Linux网络编程3&mdash;&mdash;socket
  10. [刷题codeforces]650A.637A
  11. 点评VHDL语言
  12. [转] android 中 任务、进程和线程的区别
  13. Same binary weight (位运算)
  14. jmeter 环境部署、数据库设置、分布式设置、多网卡配置等随笔
  15. Spring-hibernate-BaseDao
  16. IDEA设置优化
  17. 【XSY2680】玩具谜题 NTT 牛顿迭代
  18. [转]$.post() 和 $.get() 如何同步请求
  19. C#中用NPOI的excel导出
  20. MySQL(Innodb)索引的原理

热门文章

  1. 【idea】设置console控制台显示内容大小
  2. 使用&lt;script&gt;标签在HTML网页中插入JavaScript代码
  3. event.target.tagName
  4. js数学公式-曲线运动
  5. QT安装以及使用(QT支持linux和windows,也支持C/C++代码的编译运行,比vs简洁多)
  6. eclipse+terminal
  7. Eclipse添加git插件及操作
  8. P1020 导弹拦截 /// DP Dilworth定理 LIS、LDS优化
  9. Mybatis-generator/通用Mapper/Mybatis-Plus对比
  10. Netstat- Linux必学的60个命令