• struts2不能通过ONGL方式取出request中的Atrribute


    请看下面一个很简单的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的值。

  • 相关阅读:
    手动卸载Office2010
    css盒子模型和定位
    [转]Mysql 存储过程和函数区别
    (转载)今天面试两个人的感受
    配置apache和php mysql的一些问题
    css position[转
    drools7 (四、FactHandle 介绍)
    drools7 (三、kmodule 介绍)
    drools7 (二、agenda-group 的使用)
    drools7 (一、最简单的例子)
  • 原文地址:https://www.cnblogs.com/wuyou/p/3432111.html
Copyright © 2020-2023  润新知