2012-12-11 137 views

回答

3

顯然這兩者之間沒有區別,只是在useAttribute中可以指定預期變量的類名。

下面是​​標籤代碼:

@Override 
public void doTag() throws JspException { 
    JspContext jspContext = getJspContext(); 
    Map<String, Object> attributes = model.getImportedAttributes(JspUtil 
      .getCurrentContainer(jspContext), name, toName, ignore, 
      jspContext); 
    int scopeId = JspUtil.getScope(scopeName); 
    for (Map.Entry<String, Object> entry : attributes.entrySet()) { 
     jspContext.setAttribute(entry.getKey(), entry.getValue(), scopeId); 
    } 
} 

useAttribute標籤代碼:

@Override 
public void doTag() throws JspException { 
    JspContext pageContext = getJspContext(); 
    Map<String, Object> attributes = model.getImportedAttributes(JspUtil 
      .getCurrentContainer(pageContext), name, id, ignore, 
      pageContext); 
    if (!attributes.isEmpty()) { 
     int scopeId = JspUtil.getScope(scopeName); 
     pageContext.setAttribute(getScriptingVariable(), attributes 
       .values().iterator().next(), scopeId); 
    } 
} 
相關問題