posts - 325,  comments - 25,  trackbacks - 0

          1.<action/>result type類型:
          <!-- 配置action 返回cancle時,重定向到另一個Action-->
          <result name = "cancle" type="redirect-action">welcom</result>
          <!--配置action 返回expired時進入下一個action 連-->
          <result name= "expired" type="chain" >changepassword</result>

          2.Action中的成員屬性,并不一定只用于封裝用戶的請求參數,也可能用于封裝Action向下一個頁面的值,實際上這些值都被封裝在ValueStack中
          我們可以通過
          <%
               ValueStack vs = (ValueStack) request.getAttribute("struts.valueStack");
               Object o = (Object)vs.findValue("key");
          %>
          來獲取這些值。

          3.國際化資源文件的命名方式 basename_語言代碼_國家代碼.properties
          如果資源文件被放置到\classes\com\test下,則在struts.xml中配置加包名的引入方式
          struts.custom.i18n.resources = com.test.basename_語言代碼_國家代碼.properties

          struts2提供了兩種方式來輸出國際化信息:
              ·<s:text name="messageKey"/>
              ·<s:property value="%{getText("messageKey")}"/>

          4.struts2的ActionSupport類的validate()方法會在業務方法運行前執行,同時也提供了getText("messageKey")顯示國化際消息的方法,<s:form >也默認提供了輸出錯誤消息的功能
          public void validate(){
              if(null==this.getUserName() || "".equals(this.getUserName()){
                  addFieldError("userName",getText("user.required"));
              }
          }

          5.struts2聲明式異常處理
          <!-- 定義全局result-->
          <global-results>
              <result name="root">/exception.jsp</result>
          </global-results>
          <!--定義全局異常映射-->
          <global-exception-mappings>
              <!--當Action拋出Exception異常時,轉入root對應的視圖-->
              <exception-mapping exception="java.lang.Exception" result="root"/>
          </global-exception-mappings>
          <!--異常信息輸出-->
          在exception.jsp中,輸出異常信息
          <s:property value="exception"/> //輸出異常對象本身
          <s:property value="exceptionStack"/> //輸出異常堆棧信息

          6.struts2實現文件上傳限制的兩種方式:
              1).在action中增加如下方法

          public String filterType(String[] types)
           {
            String fileType = vo.getXXXContentType();
            for (String type : types)
            {
             if (type.equals(fileType))
             {
              return null;
             }
            }
            return INPUT;

           }

          2).在vo中增加private String allowTypes;及set get 方法
          3).execute方法中
          String filterResult = filterType(getAllowTypes().split(","));
            if (filterResult != null)
            {
             ActionContext.getContext().put("typeError" , "您要上傳的文件類型不正確!");
                 return filterResult;
            }
             if(vo.getFile().length()>1024*n){  
                  ActionContext.getContext().put("sizeError" , "您要上傳的文件過大!");
                 return filterResult;
           
              }
          4).上傳頁面中顯示的錯誤信息
              ${requestScope.typeError}
              ${requestScope.siezeError}
          5).struts.xml action中配置參數
           <param name="allowTypes">image/bmp,image/png,image/gif,image/jpeg</param>

          7.OGNL  表達式:struts2中有一個根對象  valueStack ,如果需要訪問valueStack中的屬性,要使用$ ,如${bar}
          此外,struts2還提供一些命名對象,這些命名對象與根對象無關,需要使用#訪問
          命名對象:
               parameters對象的訪問:#parameters.foo   用于返回HttpServletRequest 的getParameter("foo")的值
               request對象的訪問: #request.['foo'] 或著 #request.foo 用于返回HttpServletRequest 的getAttribute("foo")的值
               session對象的訪問:#session['foo'] 或$session.foo 用于返回HttpSession 的getAttribute("foo")的值
               application對象的訪問:#application['foo'] 或$application.foo 用于返回HttpApplication 的getAttribute("foo")的值
               attr 對象的訪問:
          8.在Action被實例化后,action對象就被保存到了ValueStack 中,所以不需要使用#就可以訪問Action的屬性

          posted on 2009-05-22 10:04 長春語林科技 閱讀(366) 評論(0)  編輯  收藏 所屬分類: struts2
          <2009年5月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 鸡泽县| 鄂尔多斯市| 通州区| 新竹市| 浦东新区| 綦江县| 临洮县| 曲水县| 堆龙德庆县| 阜新市| 图木舒克市| 聂拉木县| 海口市| 汝州市| 赣州市| 杨浦区| 秦安县| 汉寿县| 邢台县| 浮梁县| 张掖市| 晋城| 安仁县| 红河县| 邢台县| 衡水市| 祁门县| 新干县| 大悟县| 聊城市| 鹤山市| 兰考县| 开封县| 进贤县| 招远市| 仙居县| 漳州市| 天镇县| 遵义市| 穆棱市| 巴林右旗|