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

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

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

    posts - 13, comments - 7, trackbacks - 0, articles - 0
    action mapping中的attribute 屬性到底是干什么用的, 很早以前一直不太了解,今天突然又想到了這個問題,感覺不能再扔一邊不管了, 一定要解決它.


    這是在網上查到的關于attribute的解釋.
    1)應用前提,attribute只有在設置了name后才有意義。
    2)attribute可以實現對象的重用,即如果設置了attribute屬性,在創建actionform是,會先去查找相應的scope中是否有此對象,如果有,則重用,否則創建新的對象。
    3)當你將創建的acitonForm保存到相應的scope中時,你想用一個更有意義的名字來訪問它時,它就有意義了。

    可是,看到"一個更有意義的名字的時候", 我好像有點理解了
    <action
    attribute="newLoginForm"
    name="loginForm"
    type="loginAction"
    scope="request"
    path="/login">


    在struts實例化actionform的時候,struts是根據attribute的值來查找并創建actionform,有兩種情況:如果已經存在,那么從內存中取回;如果第一次實例化,那么創建,并放入內存。

    org.apache.struts.util.RequestUtils中的源代碼

    ???public static Actionform createActionform(
    ? ? ? ?HttpServletRequest request,
    ? ? ? ?ActionMapping mapping,
    ? ? ? ?ModuleConfig moduleConfig,
    ? ? ? ?ActionServlet servlet) {
    ?????? ............
    ??????............

    ???????String attribute = mapping.getAttribute();
    ??????......
    ???????Actionform instance = null;
    ? ? ? ?HttpSession session = null;

    ???????if ("request".equals(mapping.getScope())) {
    ? ? ? ? ? ?instance = (Actionform) request.getAttribute(attribute);
    ? ? ? ?} else {
    ? ? ? ? ? ?session = request.getSession();
    ? ? ? ? ? ?instance = (Actionform) session.getAttribute(attribute);
    ? ? ? ?}
    ??????................
    ????????................
    ???????
    ???????}
    ???????
    如果沒有配置attribute屬性的話, struts才會從name屬性里讀出要創建的formbean 的名字,并創建一下實例,看下邊的源代碼就知道了, 呵呵.


    org.apache.struts.config.ActionConfig

    ???protected String attribute = null;

    ? ?public String getAttribute() {
    ?//就是這里了.
    ???????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;
    ? ?}

    Feedback

    # re: 關于struts-config里action元素里的attribute屬性用途的理解  回復  更多評論   

    2008-08-07 16:58 by chenhong
    好厲害!

    # re: 關于struts-config里action元素里的attribute屬性用途的理解  回復  更多評論   

    2008-10-20 22:30 by java Primer
    很好,比起亂七八糟的書籍資料,源代碼的學習才是王道
    主站蜘蛛池模板: WWW亚洲色大成网络.COM| 色婷婷六月亚洲婷婷丁香| 午夜在线a亚洲v天堂网2019| 日韩精品久久久久久免费| 亚洲妇熟XXXX妇色黄| 亚洲免费在线观看| 亚洲中久无码永久在线观看同 | 亚洲人成电影在线观看青青| 日韩午夜理论免费TV影院| 亚洲邪恶天堂影院在线观看| 日本人成在线视频免费播放| 亚洲a在线视频视频| 日本免费一区二区三区四区五六区| 久久久久亚洲AV片无码| 91福利免费体验区观看区| 亚洲欧洲春色校园另类小说| 免费大片黄在线观看yw| 亚洲欧美国产日韩av野草社区| 日日操夜夜操免费视频| 男人免费视频一区二区在线观看| 亚洲精品无码专区2| 亚洲一区二区三区免费| 亚洲最大福利视频网站| 国产免费一区二区三区| 亚洲av中文无码字幕色不卡 | 永久看日本大片免费35分钟| 亚洲人成人77777网站不卡 | 免费黄色福利视频| 欧洲亚洲国产精华液| 国产成人亚洲综合| 亚洲毛片免费视频| 国产亚洲精品免费| 亚洲精品线在线观看| 成年女人免费视频播放77777 | 日韩亚洲国产二区| 永久免费av无码网站yy| 亚洲天堂男人影院| 亚洲人成影院在线无码按摩店| 国产成人免费在线| 未满十八私人高清免费影院| 久久亚洲春色中文字幕久久久|