Struts2源码分析(二) 一一一 StrutsRequestWrapper

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 ValueStackctx.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

相关文章:

你感兴趣的文章:

标签云: