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

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

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

    隨筆 - 22  文章 - 3  trackbacks - 0
    <2009年1月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    1、在一般情況下,actionForm是被存儲在一定的scope中(request或session,通過action的scope屬性來配置),當我們在配置時,指定name而不指定attribute,那么指定的name值就作為actionForm存儲在scope中的key值,我們可以在action中通過httpServletRequest.getAttribute("指定的name屬性值")來獲得這個actionForm;   當我們既配置了name又配置了attribute,那么actionForm存儲在scope中的key值就采用attribute屬性指定的值了,這時要通過httpServletRequest.getAttribute("指定的attribute屬性值")來獲得actionForm,此時通過httpServletRequest.getAttribute("指定的name屬性值")是不能獲得actionForm的。 
      
      所以,是否配置attribute屬性就決定了actionForm存儲在scope中的key值是采用name,還是采用attribute


     2、 在《Programming Jakarta Struts》這本書中的第四章“Configuring the Struts Application”中這樣一段說明來分別闡述這兩
    個屬性:(102頁)
    ++++++++
    atribute:
    ++++++++
    The name of the request or session scope attribute under which the form bean for this action can be accessed.
    A value is only allowed here if there is a form bean specified in the name attribute. This attribute is
    optional and has no default value.

    ++++++++
    name:
    ++++++++
    The name of the form bean, if any, that is associated with this action. This value must be the name attribute
    from one of the form-bean elements defined earlier. This attribute is optional and has no default value.

    最初看這些真的還是不好區分這兩者。不過在仔細看過struts的源代碼以后,豁然開朗。。。

    下面主要對attribute進行解釋,應為沒有人會對name屬性不了解的(呵呵。。。)


    解釋:在struts實例化actionform的時候,有兩種情況:如果已經存在,那么從內存中取回;如果第一次實例化,那么創建,并放入內存。
    這樣就有一個問題了,struts是根據什么來取回并創建actionform的呢,答案就是attribute的值。讓我們進入struts的源代碼:

    /**
    *創建或者取回formbean方法
    *該方法在:org.apache.struts.util.RequestUtils中
    */
    public static Actionform createActionform(
    HttpServletRequest request,
    ActionMapping mapping,
    ModuleConfig moduleConfig,
    ActionServlet servlet) {
    。。。。
    。。。
    // Is there a form bean associated with this mapping?
    //得到action mapping中attribute的值
    String attribute = mapping.getAttribute();
    。。。。
    。。。。
    Actionform instance = null;
    HttpSession session = null;
    //yes!!就在這里了,把創建以后的actionform放在request或者session里,看到放入的名字了么,就是mapping.getAttribute();
    if ("request".equals(mapping.getScope())) {
    instance = (Actionform) request.getAttribute(attribute);
    } else {
    session = request.getSession();
    instance = (Actionform) session.getAttribute(attribute);
    }
    。。。
    。。。


    }


    下面又有一個問題浮出水面:如果我沒有在action mapping中指定attribute呢,那struts 是如何解決的?
    答案很簡單,如果單從結果上看,此時struts使用的name的值,為什么呢,看struts源代碼:

    /**
    * The request-scope or session-scope attribute name under which our
    * form bean is accessed, if it is different from the form bean''s
    * specified <code>name</code>.
    *該代碼在:org.apache.struts.config.ActionConfig中
    */
    protected String attribute = null;

    public String getAttribute() {
    //yes!!!!就在這里,看到了吧,如果你沒有設定attribute,那么struts 會把name的值拿過來用。呵呵。。。
    if (this.attribute == null) {
    return (this.name);
    } else {
    return (this.attribute);
    }
    }

    public void setAttribute(String attribute) {
    if (configured) {
    throw new IllegalStateException("Configuration is frozen");
    }
    this.attribute = attribute;
    }


    文章出處:http://www.diybl.com/course/3_program/java/javashl/2008131/98144.html

    posted on 2009-01-13 16:31 圣克爾·光 閱讀(714) 評論(0)  編輯  收藏 所屬分類: SSH
    主站蜘蛛池模板: 亚洲日韩国产AV无码无码精品| 亚洲制服丝袜精品久久| 日韩在线视精品在亚洲| 久久久久久99av无码免费网站 | 777亚洲精品乱码久久久久久 | 国产免费私拍一区二区三区| 亚洲熟妇无码一区二区三区导航| 无码人妻一区二区三区免费手机 | 国精无码欧精品亚洲一区| 成人国产网站v片免费观看| 免费人成视频x8x8入口| 一级特黄色毛片免费看| 亚洲夜夜欢A∨一区二区三区| 丝袜足液精子免费视频| 亚洲永久永久永久永久永久精品| 最近免费中文字幕高清大全 | 美女在线视频观看影院免费天天看 | 一级毛片免费毛片毛片| 亚洲人成网站在线播放vr| 久久成人无码国产免费播放| 97亚洲熟妇自偷自拍另类图片| 最好看的中文字幕2019免费| 激情亚洲一区国产精品| 狠狠久久永久免费观看| 国产人成网在线播放VA免费| 亚洲国产精品第一区二区| 一区二区无码免费视频网站| 成a人片亚洲日本久久| 亚洲色爱图小说专区| 88xx成人永久免费观看| 亚洲婷婷第一狠人综合精品| 国产片免费福利片永久| 国产麻豆成人传媒免费观看| 亚洲一本之道高清乱码| 亚洲男人天堂2020| 91香蕉在线观看免费高清| 亚洲AV无码专区在线观看成人 | 国产精品亚洲av色欲三区| 亚洲中文字幕无码一区 | 久久成人18免费网站| 亚洲国产一区在线观看|