简单学习struts标签中使用ognl表达式
来源:互联网 发布:上海大学乐乎论坛圈子 编辑:程序博客网 时间:2024/05/22 06:38
struts2标签:
支持ognl表达式,不能使用el;
标签属性不再是纯String类型,时Object;
标签属性的类型分为Object String;
1-Object可以直接写ognl;
2-String:%{propertyName};
3-如果不清楚类型:统统加 %{},如果是Object则忽略%;
4-如果属性的类型时Object,而又想给一个固定值:如:%{'lisi'};
实现代码:
Action:
package com.handler;import java.util.ArrayList;import java.util.List;import java.util.Map;import com.bean.City;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class Action1 extends ActionSupport{private int id;private int age;private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String show(){this.age = 24;this.name = "name2";Map<String, Object> request = (Map<String, Object>)ActionContext.getContext().get("request");request.put("name", "lisi");return SUCCESS;}}前端页面获取值:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib prefix="s" uri="/struts-tags" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'show.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <% //pageContext.setAttribute("name", "lisi"); //pageContext.setAttribute("name", "zhangsan", PageContext.SESSION_SCOPE); String str = "name1"; String name1 = "aaa"; %> <s:set var="%{name}" value="%{'wangwu1'}" scope="request"></s:set> age=<s:property default="123" value="%{age}"/><br> name=<s:property value="#request.name"/><br> abc: <s:property value="#request.name2"/><br> <s:debug></s:debug> </body></html>
阅读全文
0 0
- 简单学习struts标签中使用ognl表达式
- Struts框架中OGNL标签与EL标签表达式使用
- Struts 简单UI标签,ognl表达式语言几个符号
- Ognl表达式与Struts标签
- struts中OGNL表达式
- struts标签,el表达式,ognl表达式
- Struts 2中OGNL表达式
- OGNL表达式语言和struts标签
- struts2标签中OGNL表达式(#,*,%)
- struts标签 Ognl表达式 EL表达式 jstl标签
- struts标签,ognl表达式,el表达式,jstl表达式的区别
- struts标签库中ognl表达式获取Action中对象的原理
- Struts的标签和Struts的OGNL表达式(三)
- ognl学习(二)---struts2标签库与OGNL表达式的使用
- Struts标签库结合OGNL的使用
- Struts2学习——(六)值栈与OGNL表达式[结合struts标签]
- Struts2学习总结(3)--值栈,Ognl表达式,Struts标签库,国际化,数据校验,拦截器
- Struts2学习总结(3)--值栈,Ognl表达式,Struts标签库,国际化,数据校验,拦截器
- hmtl
- 杭电acm1236 排名
- Android学习之RecyclerView
- hdu 1047 Integer Inquiry 大数加法
- 二进制与十进制的互相转换
- 简单学习struts标签中使用ognl表达式
- jquery
- 16 Three.js使用dat.GUI简化试验流程
- yum安装gcc和gcc-c++
- HDU 2276-Kiki & Little Kiki 2(矩阵快速幂+位运算)
- 时间中间键总结
- Hybrid APP混合开发的一些经验和总结
- mysql事务隔离性
- Hadoop HDFS 运行原理