StrutsRequestWrapper的源碼
public class StrutsRequestWrapper extends HttpServletRequestWrapper {
public StrutsRequestWrapper(HttpServletRequest req) {
super(req);
}
/**
* 注意下面這句註釋:獲取object,如果沒找到就去ValueStack裏面找
* Gets the object, looking in the value stack if not found
*
* @param s The attribute key
*/
public Object getAttribute(String s) {
if (s != null && s.startsWith("javax.servlet")) {
return super.getAttribute(s);
}
ActionContext ctx = ActionContext.getContext();
// ***** 調用父類的getAttribute()方法,獲取request作用域中的屬性 *****
Object attribute = super.getAttribute(s);
if (ctx != null) {
if (attribute == null) {
boolean alreadyIn = false;
Boolean b = (Boolean) ctx.get("__requestWrapper.getAttribute");
if (b != null) {
alreadyIn = b.booleanValue();
}
if (!alreadyIn && s.indexOf("#") == -1) {
try {
// ***** 如果在request中沒找到,那就去ValueStack中找 *****
// If not found, then try the ValueStack
ctx.put("__requestWrapper.getAttribute", Boolean.TRUE);
ValueStack stack = ctx.getValueStack();
if (stack != null) {
// ***** 調用findValue()方法,在ValueStack中找[先從對象棧(Value Stack Contents)中找,若沒找到,就去map棧(Stack Context)中找]
attribute = stack.findValue(s);
}
} finally {
ctx.put("__requestWrapper.getAttribute", Boolean.FALSE);
}
}
}
}
return attribute;
}
}
所以:在jsp頁面中使用EL表達式也可以訪問到struts2中ValueStack裏面的內容
在Struts2環境下,EL表達式的查找順序:
page --> request --> valueStack.findValue() --> session --> application
Struts2源碼分析(二) 一一一 StrutsRequestWrapper
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.