<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
    很好,比起亂七八糟的書籍資料,源代碼的學習才是王道
    主站蜘蛛池模板: 亚洲国产综合精品中文字幕| 亚洲精品自产拍在线观看| 美女被免费网站视频在线| 久久久久亚洲av成人无码电影 | 中文字幕成人免费高清在线| 亚洲情a成黄在线观看动漫尤物| 成人黄动漫画免费网站视频 | 在线免费视频你懂的| 亚洲中文字幕久久精品无码2021| 在线观看免费亚洲| 日本免费高清视频| 亚洲男同gay片| 亚洲人成网站在线播放影院在线| 日韩高清在线免费观看| 在线观看特色大片免费网站| 亚洲成a人片在线观看精品| 亚洲国产精品成人AV无码久久综合影院 | 久久亚洲最大成人网4438| 国产成人精品久久亚洲高清不卡 | 国产精品1024永久免费视频| 久久免费99精品国产自在现线| 亚洲a级在线观看| 亚洲成A∨人片在线观看不卡| 国产男女性潮高清免费网站| 91香蕉国产线观看免费全集| 粉色视频成年免费人15次| 亚洲另类古典武侠| 亚洲国产成人片在线观看无码| 免费观看国产小粉嫩喷水| 国产一精品一AV一免费孕妇| 一级毛片免费视频| 久久成人18免费网站| 特级av毛片免费观看| 亚洲色成人WWW永久在线观看| 亚洲伊人tv综合网色| 亚洲永久精品ww47| 亚洲视频在线免费| 免费a级毛片大学生免费观看 | 最近中文字幕免费2019| 国产日韩久久免费影院| 老妇激情毛片免费|