Thinking

          快樂(lè)編程,開(kāi)心生活
          posts - 21, comments - 27, trackbacks - 0, articles - -5
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          struts2學(xué)習(xí)Tips

          Posted on 2007-02-26 10:23 lixw 閱讀(607) 評(píng)論(2)  編輯  收藏
          1、在Action中獲得Servlet API中的對(duì)象:
          1?com.opensymphony.xwork2.ActionContext?context?=?ActionContext.getContext();
          2?HttpServletRequest?request?=?org.apache.struts2.ServletActionContext.getRequest();
          3?HttpServletResponse?response?=?org.apache.struts2.ServletActionContext.getResponse();
          4?HttpSession?session?=?request.getSession();

          ??? 獲取與Servlet運(yùn)行環(huán)境無(wú)關(guān)的Session集合:
          Map?sessionMap?=?ActionContext.getContext().getSession();
          ??? IOC方式訪問(wèn),可以通過(guò)實(shí)現(xiàn)ServletRequestAware、ServletResponseAware和SessionAware。
          參考WebWork API
          2、自定義Action調(diào)用方法:
          • 在struts.xml的action配置中,增加屬性method="aliasMethod";
          • 在訪問(wèn)Action的URL中增加!aliasMethod.action,形如 http://localhost:8080/app/ActionName!aliasMethod.action。
          3、自己布局form:
          ??? 給<s:form />增加屬性theme="simple"。

          4、WebWork中的特殊命名對(duì)象:
          ??? #prameters['foo'] or #parameters.foo??????????? ??? request.getParameter("foo");
          ??? #request['foo'] or #request.foo?? ?? ?? ?? ?? ?? ?? request.getAttribute("foo");
          ??? #session['foo'] or #session.foo?? ?? ?? ?? ?? ?? ?? session.getAttribute("foo");
          ??? #application['foo'] or #application.foo?? ?? ?? ??? application.getAttribute("foo");
          ??? #attr['foo'] or #attr.foo?? ?? ?? ?? ?? ?? ?? ?? ?? pageContext.getAttribute("foo");
          ??

          評(píng)論

          # re: struts2學(xué)習(xí)Tips  回復(fù)  更多評(píng)論   

          2007-02-26 14:09 by kawaii
          5、在webwork處理集合:
          List的語(yǔ)法:{e1,e2,e3}
          Map的語(yǔ)法:#{key1:value1,key2:value2,key3:value3}
          例如:
          <s:select label="'list'" name="'name'" list="{'name1','name2'}" />
          <s:select label="'list'" name="'name'" list="#{'foo':'foovalue', 'bar':'barvalue'}" />
          判斷一個(gè)元素是否在一個(gè)集合中可以用in和not in:
          例如:
          <ui:if test="'foo' in {'foo','bar'}">
          muhahaha
          </ui:if>
          <ui:else>
          boo
          </ui:else>
          <ui:if test="'foo' not in {'foo','bar'}">
          muhahaha
          </ui:if>
          <ui:else>
          boo
          </ui:else>

          選擇集合的一個(gè)子集, 可以在集合中使用通佩符(wildcard).

          ? 所有匹配選擇邏輯的元素
          ^ 第一個(gè)匹配選擇邏輯的元素
          $ 最后一個(gè)匹配選擇邏輯的元素

          例如:從對(duì)象Person中獲取男性親屬的子集:
          person.relatives.{? #this.gender == 'male'}

          # re: struts2學(xué)習(xí)Tips  回復(fù)  更多評(píng)論   

          2007-02-26 14:47 by kawaii
          6、國(guó)際化:
          使用全局資源文件:在struts.xml中配置
          struts.custom.i18n.resources=globalMessages;
          使用包范圍的資源文件:在類所處的包下面建立名為package.properties和
          package_zh_CN.properties的資源文件;
          使用Action范圍的資源文件:在與Action類相同的目錄下建立與Action同名
          (除過(guò)后綴)的properties文件,作為供此Action訪問(wèn)的局部資源文件;
          使用<s:i18n />標(biāo)簽。

          資源文件的查找順序參考:http://www.aygfsteel.com/max/archive/2006/11/01/78536.html

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 阿坝| 济源市| 泰兴市| 永德县| 香港 | 策勒县| 红桥区| 常熟市| 景泰县| 增城市| 阿鲁科尔沁旗| 饶河县| 恩平市| 乌恰县| 康保县| 英吉沙县| 介休市| 松原市| 牡丹江市| 博爱县| 玉山县| 新安县| 丁青县| 和林格尔县| 馆陶县| 泸水县| 云霄县| 鹿泉市| 内黄县| 和林格尔县| 琼中| 思南县| 崇州市| 凌源市| 永昌县| 任丘市| 信阳市| 西昌市| 武清区| 遂川县| 竹溪县|