<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Ordinary hut

    人間一福地,勝似天仙宮
    posts - 61, comments - 50, trackbacks - 0, articles - 1

    關于struts2的ActionContext和ValueStack的簡單理解

    Posted on 2009-04-07 20:47 landor 閱讀(3672) 評論(0)  編輯  收藏 所屬分類: struts2
    ActionContext是被存放在當前線程中的,獲取ActionContext也是從ThreadLocal中獲取的。所以在執(zhí)行攔截器、 action和result的過程中,由于他們都是在一個線程中按照順序執(zhí)行的,所以可以可以在任意時候在ThreadLocal中獲取 ActionContext。
    ActionContext包括了很多信息,比如Session、Application、Request、Locale、ValueStack等,其中 ValueStack可以解析ognl表達式,來動態(tài)后去一些值,同時可以給表達式提供對象。值棧是建立在ognl的基礎之上的。

    HttpServletRequest等對象是如何與struts2的ActionContext互通的
    是struts2重新實現(xiàn)了HttpServletRequest接口,就是類StrutsRequestWrapper,看下struts2的說明:
    All Struts requests are wrapped with this class, which provides simple JSTL accessibility. This is because JSTL works with request attributes, so this class delegates to the value stack except for a few cases where required to prevent infinite loops. Namely, we don't let any attribute name with "#" in it delegate out to the value stack, as it could potentially cause an infinite loop. For example, an infinite loop would take place if you called: request.getAttribute("#attr.foo").
    說明struts重新包裝了request接口,所以如果用request.getAttribute()的話,是執(zhí)行了StrutsRequestWrapper類,在這個類里面有訪問ActionContext的代碼:
    public class StrutsRequestWrapper extends HttpServletRequestWrapper {

        
    /**
         * The constructor
         * 
    @param req The request
         
    */
        
    public StrutsRequestWrapper(HttpServletRequest req) {
            
    super(req);
        }

        
    /**
         * 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")) {
                
    // don't bother with the standard javax.servlet attributes, we can short-circuit this
                
    // see WW-953 and the forums post linked in that issue for more info
                return super.getAttribute(s);
            }

            ActionContext ctx 
    = ActionContext.getContext();
            Object attribute 
    = super.getAttribute(s);
            

    在這里實現(xiàn)了getAttribute方法,然而沒有實現(xiàn)全部,所以只有用getAttribute方法才能獲取ActionContext中的信息
    但是它繼承了sun的HttpServletRequestWrapper類,所以其他的方法還是用的默認實現(xiàn),也就是不能訪問到ActionContext中的信息
    jstl標簽會觸發(fā)request等的getAttribute方法,所以jstl也能獲取到ActionContext的數(shù)據(jù),比如Struts2的Action中的屬性等等。
    主站蜘蛛池模板: 亚洲成AV人片在线观看无码| 亚洲国产天堂久久久久久| 久久国产亚洲观看| aa级女人大片喷水视频免费| 国产精品亚洲αv天堂无码| 成人免费观看男女羞羞视频| 免费在线观看污网站| 色吊丝性永久免费看码 | 91久久亚洲国产成人精品性色 | 久久国产美女免费观看精品| 亚洲人成伊人成综合网久久久| igao激情在线视频免费| 亚洲中文字幕在线观看| 日韩成人免费视频| 亚洲精品在线不卡| 成人毛片免费播放| 免费VA在线观看无码| 在线精品亚洲一区二区小说| 日韩电影免费在线观看| 亚洲乱码中文论理电影| 午夜a级成人免费毛片| 人人爽人人爽人人片A免费| 亚洲精品国产成人片| 91精品免费久久久久久久久| 亚洲中文字幕无码av| vvvv99日韩精品亚洲| 可以免费观看的国产视频| 亚洲国产成人超福利久久精品| 成人毛片18女人毛片免费视频未| 国产亚洲精品第一综合| 久久精品国产99精品国产亚洲性色 | 久久久久一级精品亚洲国产成人综合AV区 | 国产精品黄页在线播放免费| 乱淫片免费影院观看| 亚洲a一级免费视频| 嫩草影院免费观看| 99久久婷婷免费国产综合精品| 亚洲第一香蕉视频| 亚洲毛片网址在线观看中文字幕 | 久久精品国产亚洲AV无码麻豆 | 色偷偷亚洲第一综合网|