OGNL的相关知识
来源:互联网 发布:淘宝充值卡代理 编辑:程序博客网 时间:2024/05/17 06:48
本文主要介绍了struts2的OGNL表达式的强大功能
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@taglib prefix="s" uri="/struts-tags"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title><script>window.onload=function(){var a='<s:property value="a"/>';}</script></head><body><%request.setAttribute("p", "pppppp"); pageContext.setAttribute("r", "rrrrrrrr");%><s:property value="uname"/><s:property value="user.addr.city"/><hr/>actionContext的值:<s:property value="a"/><hr/>request的值:<s:property value="#request.b"/>另一种写法1:<s:property value="#request['b']"/>另一种写法2:<s:property value="#request[#parameters.a[0]]"/><hr/>session的值:<s:property value="#session.c"/><hr/>appliaction的值:<s:property value="#application.d"/><hr/>parameters的值:<s:property value="#parameters.a[0]"/><hr/>attr的值:<s:property value="#attr.b"/><s:property value="#attr.p"/><s:property value="#attr.r"/><hr>运算:<s:property value="2+4"/>赋值:<s:property value="#request.p=123"/>赋值后:<s:property value="#request.p"/><hr>OGNL操作集合<s:set var="list" value="{'a','b','c'}" scope="request"></s:set>list集合的值:<s:property value="#request.list.get(2)"/><hr>判断:<s:property value="'a' in #request.list"/>判断:<s:property value="'a' not in #request.list"/><hr><s:set var="map" value="#{'name':'zxs','age':#request.list.get(2)}" scope="request"></s:set>map集合的值:<s:property value="#request.map.age"/>判断:<s:property value="'age' in #request.map.keys"/>判断:<s:property value="'c' in #request.map.values"/><hr>遍历:<s:iterator value="#request.list" var="temp"><s:property value="#temp"/></s:iterator><hr>调用方法:获取PI的值:<s:property value="@@PI"/><s:debug></s:debug></body></html>
package com;import java.util.Map;import bean.Address;import bean.User;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class TestOgnlContext extends ActionSupport{private User user;private String uname;public String test1() throws Exception{setUname("zhangxiaosheng");User u=new User(1,"zxs","123456");u.setAddr(new Address("china","shanghai","changning"));setUser(u);ActionContext ac=ActionContext.getContext();ac.put("a", "actionContext的值");((Map)(ac.get("request"))).put("b","request的值");((Map)(ac.get("session"))).put("c","session的值");((Map)(ac.get("application"))).put("d","appliaction的值");return SUCCESS;}public User getUser() {return user;}public void setUser(User user) {this.user = user;}public String getUname() {return uname;}public void setUname(String uname) {this.uname = uname;}}
测试结果如图:
0 0
- OGNL的相关知识
- ValueStack相关知识(OGNL)
- struts2-ValueStack相关知识(OGNL)
- OGNL知识
- 学习OGNL的相关网站或博客
- Ognl的对象导航语言相关用法
- 相关reactjs的相关知识
- Struts2 OGNL学习知识
- OGNL一些知识
- Struts2 OGNL学习知识
- OPC的相关知识
- JDBC的相关知识
- 事务的相关知识
- 编译器的相关知识
- 编译器的相关知识
- OPC的相关知识
- IUnKnown的相关知识
- 噪音的相关知识
- Showmodal与Show的区别
- 从零开始学习jQuery (十一) 实战表单验证与自动完成提示插件
- 在Linux中创建静态库和动态库
- android Activity实现从底部弹出或滑出选择菜单或窗口
- 从零开始学习jQuery(剧场版) 你必须知道的javascript
- OGNL的相关知识
- mysql数据库编码集设置为utf8
- Java代码中调用C/C++代码
- Codeforces Problem - 13E Holes
- Enterprise User's Meeting 2014 slide
- Tomcat启动时,自动访问本地servlet
- delete this--对象请求自杀
- OpenGL ES入门详解
- Codeforces 507D (Round #287(div.2))D. The Maths Lecture【数位DP】