StrutsRequestWrapper的源码
// 核心代码:
public class StrutsRequestWrapper extends HttpServletRequestWrapper {
/**
* 注意下面这句注释:获得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
StrutsRequestWrapper的源码
// 核心代码:
public class