相信自己!

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  26 随笔 :: 3 文章 :: 13 评论 :: 0 Trackbacks

描述

WebWork允许您为所有Action配置定义一些默认的result映射,它会自动的被这个包中所有的Action以及所有扩展包继承,换句话说,如果您在多个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定义默认的结果类型.这样当使用默认结果类型时就不用指定了.如果一个包扩展另一个包,且您没有为子包指定新的默认结果类型,那么当子包的result标签中没有指定结果类型时就会使用父包中的默认类型.

<!-- 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执行情况的字符串常量.WebWork定义了一些默认结果:error, input, login, none and success.开发者当然也可以根据应用情况自由的定义结果.结果以"名字-值"的形式影射到结果类型.

结果标签

结果标签告诉WebWork在action被调用以后下一步做什么.这里是WebWork定义好的一些结果编码:

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

您可以自己扩展.大多数情况下你会用到 SUCCESSERROR ,当返回 SUCCESS 时跳转到下应用程序的一个页面.

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

...如果返回*ERROR*转向错误页面或回到前面的页面.

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

结果在xwork.xml文件中定义,嵌套在<action>标签里.如果location参数是唯一的参数,你可以这样简单的定义:

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

或简单的

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

甚至更简单

<action name="bar" class="myPackage.barAction">
<result>foo.jsp</result>
</action>
默认Action类

如果action标签中的class属性没有指定,系统默认为WebWork的ActionSupport类.

默认Location参数

如果<result ..>标签中没有param标签,如<param name="location"> ,,, </param>作为子标签.WebWork就把<result> </result>里面的文字作为location

默认返回类型

如果没有指定<result ...>标签的type属性,WebWork默认为dispatcher类型(类似于Servlet标准中的SerlvetDispatcher的forward)



    
posted on 2007-11-02 12:21 北极雪 阅读(1126) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: