OGNL语言

回到首页☞

struts2中包含以下6种对象,requestMap,sessionMap,applicationMap,paramtersMap,attr,valueStack;

  • 1)requestMap用来存放包含当前HttpServletRequest的属性(attribute)的Map,简单来说就是request域中的值;

  • 2)sessionMap用来存放包含当前HttpSession的属性(attribute)的Map

  • 3)applicationMap用来存放包含当前应用的ServletContext的属性(attribute)的Map

  • 4)paramtersMap包含当前HTTP请求参数的Map

  • 5)attr,只是用来取值,用于按request > session > application顺序访问其属性(attribute)

  • 6)valueStack值栈是Action的数据中心,关于Action中的所有Value都是存放在valueStack中.

1 、概述

OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目。 Struts2框架使用OGNL作为默认的表达式语言。
看下官方介绍:
OGNL stands for Object-Graph Navigation Language; it is an expression language for getting and setting properties of Java objects, plus other extras such as list projection and selection and lambda expressions. You use the same expression for both getting and setting the value of a property.

The Ognl class contains convenience methods for evaluating OGNL expressions. You can do this in two stages, parsing an expression into an internal form and then using that internal form to either set or get the value of a property; or you can do it in a single stage, and get or set a property using the String form of the expression directly.

2、OGNL优势

  • 1、支持对象方法调用,如xxx.doSomeSpecial();

  • 2、支持类静态的方法调用和值访问,表达式的格式:

             @[类全名(包括包路径)]@[方法名 |  值名],例如:

             @java.lang.String@format('foo %s', 'bar')@tutorial.MyConstant@APP_NAME
  • 3、支持赋值操作和表达式串联,如price=100, discount=0.8,

    calculatePrice(),这个表达式会返回80;

  • 4、访问OGNL上下文(OGNL context)和ActionContext;

  • 5、操作集合对象。

3、 小结

OGNL 有一个上下文(Context)概念,说白了上下文就是一个MAP结构,它实现了 java.utils.Map 的接口。 OgnlContext对象

  • Struts框架默认就支持Ognl表达式语言。

(struts必须引用的包:ognl.jar)

  • 作用

页面取值用。

El表达式语言,用于页面取值,jsp页面取值的标准。(默认直接可以使用)

(应用范围更广。)

Ognl表达式语言, struts标签默认支持的表达式语言。

必须配置struts标签用,不能离开struts标签直接用。

具体用法后续补充吧

回到首页☞

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值