在action方法中,调用 
    ActionContext ctx = ActionContext.getContext(); 
    ctx.put("tip", "Success"); 
    然后在JSP页面上,调用   ${requestScope.tip} 或者 <%= request.getAttribute("tip") %> 就能输出tip 的值 
    小弟刚开始看struts2 , 想知道为什么调用 ctx.put("tip", "Success") 方法,就可以把tip属性添加到 request 中? 希望各位大侠多多帮忙啊

解决方案 »

  1.   

    public void doGet(request, response) {
    先调用action的响应方法...然后...
    Set<String> keys = ActionContext.getContext().keySet();
    Iterator key_iterator = keys.iterator();
    for (key_iterato.hasNext()) {
        String key = key_iterator.next();
        request.setAttribute(key, ActionContext.getContext().get(key));
    }
    }瞎猜的...
      

  2.   

    谢谢你的回答。
    我想知道的是 ctx.put("", "");是怎样把一个属性放到request中的?在源代码里找了好久也没有找到相关的语句
    对于session,通过以下语句,application也是一样的,但在ActionContext中没有getRequest()方法,所有比较晕。。ActionContext.getSession()方法返回sessionMap
    public Map<String, Object> getSession() {
            return (Map<String, Object>) get(SESSION);
        }sessionMap 中的put方法,调用session.setAttribute(key.toString(), value);
    public V put(K key, V value) {
            synchronized (this) {
                if (session == null) {
                    session = request.getSession(true);
                }
            }
            synchronized (session) {
                V oldValue = get(key);
                entries = null;
                session.setAttribute(key.toString(), value);
                return oldValue;
            }
        }