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. Android-自定义开关

    效果图: 需要两张图片,一张图片为背景,一张图片为滑动的点 布局去指定一个自定义View对象: view.custom.shangguigucustomview.MyCustomSwitch < ...

  2. Sqlite 快速插入数据到本地表中

    用原始Insert方法太慢,网上找到了https://www.cnblogs.com/yisen-code/p/6897524.html 思路是: 开启事务,开启预处理,然后把SQL用参数传入具体值来 ...

  3. SelectOnCheck

    1.checkOnSelect 如果为true,当用户点击行的时候该复选框就会被选中或取消选中. 如果为false,当用户仅在点击该复选框的时候才会呗选中或取消. 2.selectOnCheck 如果 ...

  4. layui json数据格式要求

    layui  数据格式要求 layui有自己的一套特定的数据格式交互(这很重要),必须参数code:0,msg:“”,count:数据size(int),data:”数据List”.一般我们选择封装返 ...

  5. Java Web 学习与总结(三)会话跟踪

    何为会话跟踪?举个简单的例子,比如登陆到某购物网站后,在一定时间内无论你在这个网站中切换到任意的网页,只要不执行退出操作,一直保持着你账号的登录状态. 那么在Java Web中我们应当如何去实现这一操 ...

  6. Nodejs Express模块server.address().address为::

    来自 http://blog.csdn.net/medivhq/article/details/74171939 我按照菜鸟教程上的写法为:(http://www.runoob.com/nodejs/ ...

  7. Linux中一些 不是很常用的配置修改

    1,让虚拟机屏幕最大化 :查看-->自动调整大小-->自动适应客户机 2,让虚拟机取消屏保: system --> preferences --> Screensaver

  8. 高可用群集HA介绍与LVS+keepalived高可用群集

    一.Keepalived介绍 通常使用keepalived技术配合LVS对director和存储进行双机热备,防止单点故障,keepalived专为LVS和HA设计的一款健康检查工具,但演变为后来不仅 ...

  9. Nginx+SpringBoot搭建负载均衡

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  10. 孩子们各显神通对付 iOS 12「屏幕使用时间」的限制

    简评:2018 年秋季,苹果公司推出了 iOS 12,其中备受好评的一项改变是:增加了屏幕使用时间限制,以减轻沉迷手机的状况.三个月过去后,这项功能似乎并没有对孩子造成太多困扰,道高一尺魔高一丈,孩子 ...