1.取出request,session,applicaiton中的值

  a.往里面加入request,session,application中加入值

	public String testServlet(){
ServletActionContext.getRequest().setAttribute("request_username", "username");
ActionContext.getContext().getSession().put("session_username", "username");
ServletActionContext.getServletContext().setAttribute("application_username","username"); return "servlet";
}

  取值:

   	输出request,session,application域中的值,由于访问的是map,所以要加个#号<br>
request的值:<s:property value="#request.request_username" /><br>
session的值:<s:property value="#session.session_username" /><br>
application的值:<s:property value="#application.application_username" /><br>

  

2.用valuestack中的对象栈的set方法存放的数据,把对象封装成一个hashmap,放入栈顶

  a.放值

	public String testValueStack_Set(){
ValueStack valueStack = ActionContext.getContext().getValueStack();
valueStack.set("msg", "message");
return "value_stack_set";
}

  b.取值

   	输出valuestack的set方法存放的数据,实际输出的是栈顶的数据<br>
<s:property value="msg"/><br>

  

3.    在person,student和ognlAction中同时有commit,测试页面会输出栈中第一个commit,也就是OgnlAction中的commit

  a.放值,用add方法放

	public String testValueStack_Deep(){
Person person=new Person();
person.setAge(new Integer(1));
person.setName("person");
person.setCommit("person"); Student student=new Student();
student.setAge(2);
student.setName("student");
student.setCommit("student"); ValueStack valueStack = ActionContext.getContext().getValueStack();
CompoundRoot root = valueStack.getRoot();
root.add(person);
root.add(student); return "valueStack_deep"; }

  取值:

   	在person,student和ognlAction中同时有commit,测试页面会输出栈中第一个commit,也就是OgnlAction中的commit
<s:property value="commit"/>

  

4.在对象栈中person对象作为key,利用set方法存放在对象栈的栈顶,取出它的name属性

  a.存放数据

	public String testObjectToRoot_Set(){
Person person=new Person();
person.setAge(new Integer(1));
person.setName("person");
person.setCommit("person");
ValueStack valueStack = ActionContext.getContext().getValueStack();
valueStack.set("person", person);
return "root_set";
}

  b.取出数据

   	<s:property value="person.name" /><br>

  

5.构造map,在页面上构造map

   	构造map:<br>
<!--
这个标签对应的html代码
<input type="radio" id="fool" value="fool"/><label for="fool">bool</label>
<input type="radio" id="foo2" value="foo2"/><label for="foo2">boo2</label>
从上面可以看出,map中key相当于radio中的value和id,map中的value相当于页面上显示的值
-->
<s:radio list="#{'fool':'bool','foo2':'boo2' }"></s:radio><br>

  

6.构造map,在后台构造map,然后存放在request域中,在页面取出来

  a.构造map,放入request域中

	public String testMap_Request(){
Map<String,String> map=new HashMap<String, String>();
map.put("male", "男");
map.put("girl","女"); ServletActionContext.getRequest().setAttribute("map", map);
return "map_request";
}

  b.在页面取出来

   	 从request域中获取map<br>
<s:property value="#request.map.male"/><br>

  

7.用put方法保存map至context中的map

  a.存放map

	public String testMap_Put(){
ActionContext context = ActionContext.getContext();
Map<String,String> map=new HashMap<String, String>();
map.put("male", "男");
map.put("girl","女");
context.put("map",map);
return "map_put"; }

  b.取出map中的数据

   	 从map中取出利用put方法存放的map<br>
<s:property value="#map.male"/><br>

  

8.把一个字符串放到request域中,然后用%输出

  a.存放数据

	public String testRequest_Percent(){
ServletActionContext.getRequest().setAttribute("request_username","username");
return "request_percent";
}

  b.取出数据

   	 利用%输出request域中的内容<br>
<s:textfield name="username" label="%{#request.request_username}"></s:textfield><br>

  

Strut2 ognl取出存放在request,session,application和对象栈的中的值的更多相关文章

  1. request,session,application

    JSP 的3个内置对象request,session,application,其实都有一个作用域,这些对象内部有一个Map成员用于存放数据,比如session对象的setAttribute(key,v ...

  2. struct2访问或添加request/session/application

    访问或添加request/session/application 1 通过ActionContext //这样放置 public String execute()  {     ActionConte ...

  3. request, session, application辨析(待更新)

    作用域 request < session < application 分析 1. request 只在一次请求中有效,当请求发送变化时,信息将失效. 2. session 在当前一次会话 ...

  4. Struts2里如何取得request,session,application

    第一种:取得MAP类型的request,session,application在java文件里写 package com.xjtu.st; import java.util.Map; import c ...

  5. page,request,session,application四个域对象的使用及区别

    转自:page,request,session,application四个域对象的使用及区别 1.page指当前页面.只在一个jsp页面里有效 .2.request 指从http请求到服务器处理结束, ...

  6. JavaWeb -pageContext/request/session/application

    pageContext/request/session/application总结 一.范围差异 1. pageContext jsp页面容器 当前页面有效 2. request 请求对象 同一次请求 ...

  7. Struts2初学 Struts2在Action获取内置对象request,session,application(即ServletContext)

    truts2在Action中如何访问request,session,application(即ServletContext)对象???? 方式一:与Servlet API解耦的方式      可以使用 ...

  8. struts2标签获取parameter,request,session,application中的值

    http://localhost:8080/demo/index.jsp?flag=kkkk <s:property value="#parameters.flag" /&g ...

  9. struts2 action中获取request session application的方法

    共四种方式: 其中前两种得到的是Map<String,Object>  后两种得到的才是真正的request对象 而Map就是把request对象中的属性取出做成了键值对而已. [方法一] ...

随机推荐

  1. R12 查询EBS用户相关SQL

    --R12查询EBS在线用户SQL SELECT U.USER_NAME,       APP.APPLICATION_SHORT_NAME,       FAT.APPLICATION_NAME,  ...

  2. ServiceStack.Text json中序列化日期格式问题的解决

    标记: ServiceStack.Text,json,序列化,日期 在使用ServiceStack.Text的序列化为json格式的时候,当属性为datetime的时候,返回的是一个new date( ...

  3. python 中为什么不需要重载

    函数重载主要是为了解决两个问题. (1)可变参数类型. (2) 可变参数个数. 另外,一个基本的设计原则是,仅仅当两个函数除了参数类型和参数个数不同以外,其功能是完全相同的,此时才使用函数重载,如果两 ...

  4. eFrameWork学习笔记-eOleDB

    eOleDB是eFrameWork框架下基础的数据访问类,用于执行SQL语句,返回DataTable,分页,返回数据库所有库,库的所有表,表的所有列,Json导入.导出等. HTML: <div ...

  5. java学习笔记—ServletConfig、ServletContext接口(13)

    ServletConfig是一个由Tomcat服务器在初始化Servlet的时候创建并传递进来的一个对象. 该对象主要描述的时候一个servlet的配置信息. 如: <servlet>  ...

  6. Problem H: 小姐姐的QQ号(DFS)

    Contest - 河南省多校连萌(四) Problem H: 小姐姐的QQ号 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 297  Solved:  ...

  7. Java多线程编程 — 锁优化

      阅读目录 一.尽量不要锁住方法 二.缩小同步代码块,只锁数据 三.锁中尽量不要再包含锁 四.将锁私有化,在内部管理锁 五.进行适当的锁分解 正文 并发环境下进行编程时,需要使用锁机制来同步多线程间 ...

  8. acedSSSetFirst选择集夹点亮显实例

    ads_name ss; //执行预选 好像可以无视PICKSTYLE变量 if (RTNORM != acedSSGet(_T("I"),NULL,NULL,NULL,ss)) ...

  9. Python面向对象(定义类和创建对象)

    day24 http://www.cnblogs.com/wupeiqi/p/4493506.html Python:函数式+面向对象,函数式编程可以做所有事,但是不一定合适. 小明,10岁,男,上山 ...

  10. Redis Sentinel初体验

        自Redis增加Sentinel集群工具以来,本博主就从未尝试过使用该工具.最近在调研目前主流的Redis集群部署方案,所以详细地看了一遍官方对于Sentinel的介绍并在自己的台式机上完成了 ...