请问这个attr从何而来?谢谢

=======generatorTag.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



generator标签使用范例



generator标签使用范例



/s:generator








/s:iterator

======index.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>


<%
String contextPath = request.getContextPath();
%>

http://struts.apache.org/dtds/struts-2.0.dtd">



<!-- 直接导航的的Action定义 -->

/jsp/appendTag.jsp



/jsp/generatorTag.jsp


/jsp/ifelseifTag.jsp


/jsp/iteratorTag.jsp


/jsp/mergeTag.jsp



/jsp/sortTag.jsp


/jsp/subsetTag.jsp



attr是struts2添加到值栈的上下文取的一个Map(org.apache.struts2.util.AttributeMap)

这个attr包含4个作用域:

  • A Map that holds 4 levels of scope.
  • The scopes are the ones known in the web world.:
    • Page scope
    • Request scope
    • Session scope
    • Application scope

    Dispatcher.java struts2在执行action之前默认放到上下文的 ActionContext
    [code="java"] // helpers to get access to request/session/application scope
    extraContext.put("request", requestMap);
    extraContext.put("session", sessionMap);
    extraContext.put("application", applicationMap);
    extraContext.put("parameters", parameterMap);

        AttributeMap attrMap = new AttributeMap(extraContext);
        extraContext.put("attr", attrMap);
    

    [/code]

    按照这个顺序查找属性,顺序是page--->request----->session---->application;

    也就是说通过ActionContext.getContext.get("attr") 是可以获取的到的。

    #attr 是ognl表达式,用于访问上下文数据的。

    看这段代码,attr变量是存在于这个页面中的。

    没有引入其他页面的话就,看环境的全局变量

    如果还解决不了问题你可以输出一下这个变量值看看,根据经验判断是什么玩意,再找变量的实例是从哪里加到页面的,