Struts2源碼分析(一) 一一一 StrutsRequestWrapper

來源:互聯網
上載者:User

標籤:strutsrequestwrapper   struts2   

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裡面的內容EL運算式的尋找順序:page --> request --> valueStack.findValue() --> session --> application

Struts2源碼分析(一) 一一一 StrutsRequestWrapper

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.