OGNL相关代码

时间:2023-03-09 18:31:22
OGNL相关代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body> <%
application.setAttribute("app", "application的内容");
session.setAttribute("ses", "会话的测试");
request.setAttribute("req", "request的内容"); application.setAttribute("ses", "123123");
session.setAttribute("app", "会话的测12313试"); %>
<a href=""></a> <a href="test?userID=9999&date=123">下一个页面</a> <a href="testtag?userID=aaaaa">下一个页面</a> </body>
</html>
<%@page import="java.util.Date"%>
<%@page import="com.opensymphony.xwork2.util.ValueStack"%>
<%@page import="com.opensymphony.xwork2.ActionContext"%>
<%@ 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=UTF-8">
<title>Insert title here</title>
</head>
<body> <%
ActionContext ac = ActionContext.getContext(); ValueStack vs = ac.getValueStack(); //弹出顶部的对象
//Date dt = (Date)vs.pop(); //得到顶部对象
//Date dt = (Date)vs.peek();
//out.print(dt); %> 使用OGNL访问值栈
<br><br> EL方式
${date }<br>
${userID }
<br>
访问map栈
${sessionScope.ses } <br>
标签方式
<s:property value='[1]["date"]'/>
<s:property value= "userID"/>
<br>
<s:property value="[1].date"/>
<br> <s:property value="[0].userID"/> <br>
输出顶部对象
<s:property/> <br>
访问map栈
<s:property value="#session.ses"/>
<br>
<s:property value="#parameters.userID"/>
<br>
<s:property value= "#application.app"/>
<br>
<s:property value= "#request.req"/>
<br>
<s:property value= "#attr.ses"/> <br>
调用实例方法:
产生随机数=<s:property value="[0].nextInt(100)"/> <br>
调用静态属性和静态方法:
随机数=<s:property value="@java.lang.Math@random()"/>
<br>
PI=<s:property value="@java.lang.Math@PI"/>
<br> 访问List类型的对象
<br>
List的长度=<s:property value="[0].size()"/>
<br>
<s:property value="[0].get(0)"/> <br><br>
访问对象的集合属性
长度=<s:property value="[0].myList.size()"/>
<br>
内容=<s:property value= "[0].myList[]"/>
<br>
内容0=<s:property value= "[0].myList[0]"/>
<br>
是否为空=<s:property value="[0].myList.isEmpty"/> <!-- 打印到界面 -->
<s:debug></s:debug> </body>
</html>