Thinking

          快樂編程,開心生活
          posts - 21, comments - 27, trackbacks - 0, articles - -5
            BlogJava :: 首頁 :: 新隨筆 :: 聯(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)境無關(guān)的Session集合:
          Map?sessionMap?=?ActionContext.getContext().getSession();
          ??? IOC方式訪問,可以通過實(shí)現(xiàn)ServletRequestAware、ServletResponseAware和SessionAware。
          參考WebWork API
          2、自定義Action調(diào)用方法:
          • 在struts.xml的action配置中,增加屬性method="aliasMethod";
          • 在訪問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的語法:{e1,e2,e3}
          Map的語法:#{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、國際化:
          使用全局資源文件:在struts.xml中配置
          struts.custom.i18n.resources=globalMessages;
          使用包范圍的資源文件:在類所處的包下面建立名為package.properties和
          package_zh_CN.properties的資源文件;
          使用Action范圍的資源文件:在與Action類相同的目錄下建立與Action同名
          (除過后綴)的properties文件,作為供此Action訪問的局部資源文件;
          使用<s:i18n />標(biāo)簽。

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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 灵宝市| 额敏县| 和平区| 枝江市| 介休市| 信阳市| 金塔县| 陇川县| 新巴尔虎右旗| 临西县| 永济市| 塘沽区| 嘉黎县| 开平市| 大田县| 休宁县| 澜沧| 庆城县| 武夷山市| 黑龙江省| 深水埗区| 长沙县| 青冈县| 剑河县| 巢湖市| 平利县| 遂昌县| 西藏| 武冈市| 外汇| 炎陵县| 松桃| 绍兴市| 德令哈市| 芜湖县| 盖州市| 营口市| 灵寿县| 南皮县| 白沙| 本溪|