相信自己!

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            26 隨筆 :: 3 文章 :: 13 評(píng)論 :: 0 Trackbacks

          描述

          WebWork允許您為所有Action配置定義一些默認(rèn)的result映射,它會(huì)自動(dòng)的被這個(gè)包中所有的Action以及所有擴(kuò)展包繼承,換句話說(shuō),如果您在多個(gè)Action中使用相同的result映射,您可以把它配置成全局的Result.

          例子

          <package name="default">
          ....
          <global-results>
          <result name="login" type="dispatcher">
          <param name="location">login.jsp</param>
          </result>
          </global-results>
          <action name="foo"  class="mypackage.fooAction">
          <result name="success" type="dispatcher">bar.jsp</result>
          </action>
          <action name="submitForm"  class="mypackage.submitFormAction">
          <result name="success" type="dispatcher">submitSuccess.jsp</result>
          </action>
          ...
          </package>

          這樣配置也可以

          <package name="default">
          ....
          <action name="foo"  class="mypackage.fooAction">
          <result name="success" type="dispatcher">bar.jsp</result>
          <result name="login" type="dispatcher">login.jsp</result>
          </action>
          <action name="submitForm"  class="mypackage.submitFormAction">
          <result name="success" type="dispatcher">submitSuccess.jsp</result>
          <result name="login" type="dispatcher">login.jsp</result>
          </action>
          ...
          </package>


          描述

          在WebWork中您可以為您的Action定義默認(rèn)的結(jié)果類型.這樣當(dāng)使用默認(rèn)結(jié)果類型時(shí)就不用指定了.如果一個(gè)包擴(kuò)展另一個(gè)包,且您沒(méi)有為子包指定新的默認(rèn)結(jié)果類型,那么當(dāng)子包的result標(biāo)簽中沒(méi)有指定結(jié)果類型時(shí)就會(huì)使用父包中的默認(rèn)類型.

          <!-- parts of xwork.xml  -->
          ....
          <result-types>
          <result-type name="dispatcher" class="com.opensymphony.webwork.dispatcher.ServletDispatcherResult" default="true"/>
          <result-type name="redirect" class="com.opensymphony.webwork.dispatcher.ServletRedirectResult"/>
          <result-type name="velocity" class="com.opensymphony.webwork.dispatcher.VelocityResult"/>
          </result-types>
          ....
          <action name="bar" class="myPackage.barAction">
          <!-- this result uses dispatcher, so you can omit the type="dispatcher" if you want -->
          <result name="success">foo.jsp</result>
          <!-- this result uses velocity result, so the type needs to be specified -->
          <result name="error" type="velocity">error.vm</result>
          </action>
          ....
              

          描述

          Result是Action返回的表示Action執(zhí)行情況的字符串常量.WebWork定義了一些默認(rèn)結(jié)果:error, input, login, none and success.開(kāi)發(fā)者當(dāng)然也可以根據(jù)應(yīng)用情況自由的定義結(jié)果.結(jié)果以"名字-值"的形式影射到結(jié)果類型.

          結(jié)果標(biāo)簽

          結(jié)果標(biāo)簽告訴WebWork在action被調(diào)用以后下一步做什么.這里是WebWork定義好的一些結(jié)果編碼:

          String SUCCESS = "success";
          String NONE    = "none";
          String ERROR   = "error";
          String INPUT   = "input";
          String LOGIN   = "login";

          您可以自己擴(kuò)展.大多數(shù)情況下你會(huì)用到 SUCCESSERROR ,當(dāng)返回 SUCCESS 時(shí)跳轉(zhuǎn)到下應(yīng)用程序的一個(gè)頁(yè)面.

          <result name="success" type="dispatcher">
          <param name="location">/thank_you.jsp</param>
          </result>

          ...如果返回*ERROR*轉(zhuǎn)向錯(cuò)誤頁(yè)面或回到前面的頁(yè)面.

          <result name="error" type="dispatcher">
          <param name="location">/error.jsp</param>
          </result>

          結(jié)果在xwork.xml文件中定義,嵌套在<action>標(biāo)簽里.如果location參數(shù)是唯一的參數(shù),你可以這樣簡(jiǎn)單的定義:

          <action name="bar" class="myPackage.barAction">
          <result name="success" type="dispatcher">
          <param name="location">foo.jsp</param>
          </result>
          </action>

          或簡(jiǎn)單的

          <action name="bar" class="myPackage.barAction">
          <result name="success" type="dispatcher">foo.jsp</result>
          </action>

          甚至更簡(jiǎn)單

          <action name="bar" class="myPackage.barAction">
          <result>foo.jsp</result>
          </action>
          默認(rèn)Action類

          如果action標(biāo)簽中的class屬性沒(méi)有指定,系統(tǒng)默認(rèn)為WebWork的ActionSupport類.

          默認(rèn)Location參數(shù)

          如果<result ..>標(biāo)簽中沒(méi)有param標(biāo)簽,如<param name="location"> ,,, </param>作為子標(biāo)簽.WebWork就把<result> </result>里面的文字作為location

          默認(rèn)返回類型

          如果沒(méi)有指定<result ...>標(biāo)簽的type屬性,WebWork默認(rèn)為dispatcher類型(類似于Servlet標(biāo)準(zhǔn)中的SerlvetDispatcher的forward)



              
          posted on 2007-11-02 12:21 北極雪 閱讀(1136) 評(píng)論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 太仆寺旗| 密云县| 奉化市| 宁化县| 安顺市| 芦山县| 仙游县| 伊春市| 区。| 万载县| 榆林市| 顺昌县| 松原市| 宣汉县| 黑龙江省| 丘北县| 商河县| 铁岭县| 牟定县| 慈溪市| 邛崃市| 西青区| 金湖县| 崇明县| 怀宁县| 大余县| 永吉县| 陈巴尔虎旗| 临安市| 农安县| 竹北市| 西宁市| 永川市| 高淳县| 新竹市| 清新县| 墨江| 绩溪县| 镇坪县| 开封县| 汾西县|