请看下面一个很简单的Action

package com.ahgw.main.action;

import org.springframework.stereotype.Controller;

/**
* Created with IntelliJ IDEA.
* User: HYY
* Date: 13-11-19
* Time: 下午7:08
* To change this template use File | Settings | File Templates.
*/
@Controller
public class Test2Action {
private String hyy; public String execute() {
System.out.println("hyy = " + hyy);
return "success";
} public String getHyy() {
return hyy;
} public void setHyy(String hyy) {
this.hyy = hyy;
}
}

一般来说,如果request有hyy这个parameter,那么可以获取该值。然后如果request中仅有key为hyy的Atrribute,那么这一段代码是获取不了该值的。

请继续看:

public class TestInterceptor extends AbstractInterceptor {

    @Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
HttpServletRequest request = (HttpServletRequest) actionInvocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);
request.setAttribute("hyy", "heyiyong");
System.out.println("经过测试拦截器");
return actionInvocation.invoke();
}
}
        <interceptors>
<interceptor name="testInterceptor" class="com.ahgw.admin.interceptor.TestInterceptor"></interceptor>
</interceptors> <action name="test2Action" class="test2Action">
<interceptor-ref name="testInterceptor"></interceptor-ref>
<result>/test.jsp</result>
</action>

了解清楚后,在浏览器输入/test2Action.do发现输出如下:

经过测试拦截器
hyy = null

总结:在struts2的action中,通过OGNL方式不能获取atrribute而只能获取到parameter的值。

struts2不能通过ONGL方式取出request中的Atrribute的更多相关文章

  1. struts2 2.5.16 通配符方式调用action中的方法报404

    1.问题描述 在struts.xml中配置用通配符方式调用action中的add()方法,访问 http://localhost:8080/Struts2Demo/helloworld_add.act ...

  2. struts2:数据校验,通过Action中的validate()方法实现校验,图解

    根据输入校验的处理场所的不同,可以将输入校验分为客户端校验和服务器端校验两种.服务器端验证目前有两种方式: 第一种 Struts2中提供了一个com.opensymphony.xwork2.Valid ...

  3. jplayer中动态添加列表曲目(js提取request中的list数据作为js参数使用)

    jplayer 的播放列表使用如下: $(document).ready(function(){ new jPlayerPlaylist({ jPlayer: "#jquery_jplaye ...

  4. Request中Attribute 和 Parameter 的区别

    Attribute 和 Parameter 的区别 (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为 ...

  5. request中获取post的json对象数据content-type=“text/plain”

    其实采用http://www.cnblogs.com/SimonHu1993/p/7295750.html中的方法一都能获取到,就是通过获取request中的流数据,拿到json数据,理论上应该适用各 ...

  6. request中的那些方法到底是干什么的?

    最近做Java Web项目,在.jsp页面和servlet之间request和response还是有些混淆,查阅了一些资料,总结如下,方便以后使用: 首先,servlet接口是最基本的,提供的五个方法 ...

  7. 取出session中的所有属性与值的方法

    如果你想取出session中所有的属性和值,可以通过getAttributeNames()方法来实现,具体代码如下 //获取session HttpSession session = request. ...

  8. Request中的各种方法

    前言 Request中方法众多,对于Java Web程序员来说,种种方法都会在工作中常常用到.Request由于不是JDK的一部分,这些方法的用法也没有专门的API可以查,所以在工作中遇到Reques ...

  9. struts2 servlet api 访问方式

    Action中访问ServletAPI. 主要就是接收表单参数及向域对象中存取值. 关于SevletAPI的方法在Action中有三种方式: 1.完全解耦合的形式: * 使用一个类:ActionCon ...

随机推荐

  1. 最简单的自定义适配器adapter

    下面是一个非常简单的自定义适配器的总体源码,从这个源码入门,就可以慢慢学会适配器了 适配器的作用: 完成数据和界面控件的绑定,把数据绑定到界面的现实控件条目上(对于listView,应该是listVi ...

  2. Cocos2d-x中获取设备语言的方法

    1.cocos2dx获取设备语言的方法:CCApplication::sharedApplication()->getCurrentLanguage() 2.cocos2dx 2.1.4支持识别 ...

  3. Director Scene Layer and Sprite

    Scenes Director Layers Multiple Layers Example: Sprites References Scenes A scene (implemented with ...

  4. Java Interview Reference Guide--reference

    Part 1 http://techmytalk.com/2014/01/24/java-interview-reference-guide-part-1/ Posted on January 24, ...

  5. 深入理解iframe

    本文并不是一篇iframe API文档讲解,因此想了解iframe API的同学请移步 MDN, 我将在现在浏览器的角度与大家取探讨iframe, 因此,本文中虽然会提及一些iframe在旧浏览器中的 ...

  6. centos6.6 install

    文中下载链接以中断 请另行下载 #!/bin/bash rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8. ...

  7. Linux文件/目录权限整理

  8. PL/SQL Developer 远程连接Oracle数据库

    PL/SQL Developer 远程连接Oracle数据库 网上搜了很多方法,这个可行! 1.    配置服务器tnsnames.ora文件,如果本机上没有安装oracle,可以从安装了oracle ...

  9. setTimeout 和 setInterval区别

    setTimeout和setIntelval都有定时的功能!!!取消定时功能的时候,都有对应的clearTimeout以及clearInterval与之对应. 但是他们之间是有区别的! setTime ...

  10. Linq- ExcuteQuery用法

    DataContext.ExecuteQuery<TResult> 方法 (String, Object[]) 语法: public IEnumerable<TResult> ...