Struts2OGNL
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顺序查找
Struts2OGNL的更多相关文章
- struts2-ognl 访问静态方法
在内网基本上还真没看到有哥们发现这个问题, 在google上有的哥们说 这是 v 2.3.20的一个bug, 有的人说在该版本中已经不建议通过ognl方式访问静态方法了. 对于这两种说法, 我比较赞同 ...
- Struts2---OGNL表达式和EL表达式
在action里放入actioncontext的变量值 ActionContext.getContext().put("forumList", forumList); 在jsp里如 ...
- struts2OGNL表达式(三)
OGNL表达式 OGNL对象试图导航语言.${user.addr.name}这种写法就叫对象试图导航.Struts框架使用OGNL作为默认的表达式语言 OGNL不仅仅可以试图导航,支持比EL表达式更加 ...
- 4.Struts2-OGNL
/*ognl 是 strut2 特有的表达式,使用 ognl,struts2 就无需将对象手动放值进request等范围,页面(从值栈中)直接传值*/ OGNL <?xml version=&q ...
- struts2-OGNL表达式-OGNL与Struts2的结合
1 OGNL表达式 OGNL:对象视图导航语言. ${user.addr.name} 这种写法就叫对象视图导航.OGNL不仅仅可以视图导航.支持比EL表达式更加丰富的功能. 1.1 使用OGNL 导包 ...
- Structs框架
一.准备工作及实例 1.解压struts-2.1.6-all.zip(structs网上下载) apps目录:struts2自带的例子程序 docs目录:官方文档. lib 目录:存放所有jar文件. ...
- struts2.1.6教程四、OGNL与ValueStack(VS)
1.值栈入门 下面我们建立struts2ognl项目来练习ognl的使用. 步骤一.搭建strust2的开发环境 步骤二.建立LoginAction,主要代码如下: package com.asm; ...
- OGNL表达式(转载)
OGNL表达式(转载) 1.什么是OGNL OGNL:Object Graphic Navigation Language(对象图导航语言) 它是Struts2中默认的表达式语言.使用表达式需要借 ...
- 18.OGNL与ValueStack(VS)-值栈入门
转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 下面我们建立struts2ognl项目来练习ognl的使用. 步骤一.搭建s ...
随机推荐
- Spark中的各种action算子操作(java版)
在我看来,Spark编程中的action算子的作用就像一个触发器,用来触发之前的transformation算子.transformation操作具有懒加载的特性,你定义完操作之后并不会立即加载,只有 ...
- webpakc4.0移除了 CommonsChunkPlugin 组建
在4.0之前我们可以通过 require('webpack.optimize.CommonsChunkPlugin'); 这样引入 CommonsChunkPlugin 组建对第三方模块进行独立打 ...
- 安装Epson打印机但因lsb依赖错误而中断的驱动程序
sudo apt-get install printer-driver-escpr 安装Epson打印机但因lsb依赖错误而中断的驱动程序 问题: 我正在安装 Epson XP-310 驱动程序,从这 ...
- vue中获取节点.
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- js获取当前网址Url
js获取当前路径并截取 var str = window.location.href;// str = 'https://localhost:8080/mark' var index = str .l ...
- 用shell脚本执行php删除缓存文件
<?php #定义删除路径//服务器缓存目录的路径 $path = '/www/wwwroot/****/data/runtime'; #调用删除方法 deleteDir($path); fun ...
- id(), is, ==, 的区别与小数据池
1. id() 内存地址 s = 'asdf' n = id(s) print(n)输出:16506464 #16506464为变量s的内存地址 2. == 比较数值 3. is 比较内存地址 数字, ...
- Caused by: java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties;
报错信息 Error starting ApplicationContext. To display the auto-configuration report re-run your applica ...
- day3:python运算符及数据类型(str)(int)
运算符 算数运算 :a = 10 * 10赋值运算:a = a + 1 a+=1 比较运算:a = 1 > 5 逻辑运算: a = 1>6 or 1==1 a = 1 and b = ...
- python编码(31-01)
以什么方式编码,就以什么方式解码! 第一种编码与解码方式: encode()编码 decode()解码 type()查看数据类型 repr()查看数据内容 s = '你好'print(type(s)) ...