美文网首页struts2
struts2 ognl表达式入门

struts2 ognl表达式入门

作者: DouDouZH | 来源:发表于2018-05-15 10:07 被阅读0次

一、概述

1、之前的el表达式在jsp中获取域对象的值
2、ognl是一种表达式,这个表达式功能更加强大
3、ognl表达式的特点

  • 支持对象方法调用,例如:objName.methodName()
  • 支持类静态方法的表用和值访问表达式格式为@[类全名(包括路径)]@[方法名|值名],例如:@java.lang.String@format('foo%s','bar')
  • 支持赋值操作和表达式串联
  • 访问ognl上下文(ognl context)和ActionContext
  • 操作集合对象

4、主要用途

  • 在struts2里面操作值栈数据
  • 一般把ognl和struts2标签一起使用操作值栈

5、ognl不是struts2的一部分,是一个单独的项目,经常和struts2一起使用

  • 使用ognl时首先导入jar包,struts2提供jar包

二、入门案例使用ognl+strust2实现计算字符串长度

在java中调用字符串.length();

1、使用struts2标签,在jsp中引入标签库
<%@ taglib uri="/struts-tags" prefix="s" %>  
2、使用struts2标签实现功能
<!-- 使用ognl+struts2实现计算字符串长度
         valu属性值:ognl表达式
     -->
    <s:property value="'zhangsan'.length()"/>
3、显示效果
image.png

相关文章

网友评论

    本文标题:struts2 ognl表达式入门

    本文链接:https://www.haomeiwen.com/subject/ogfedftx.html