Result Configuration --Result 配置

  当一个操作类方法完成后,它将返回一个字符串。字符串的值是用来选择一个元素的结果。一个操作映射的结果往往会有一组代表不同的可能的结果。一组标准的结果令牌由ActionSupport定义基类。

 String SUCCESS = "success";
String NONE = "none";
String ERROR = "error";
String INPUT = "input";
String LOGIN = "login";
 <!--Setting a default Result Type-->

 <result-types>
<result-type name="dispatcher" default="true"
class="org.apache.struts2.dispatcher.ServletDispatcherResult" />
</result-types> <!-- If a type attribute is not specified, the framework will use the default dispatcher type, which forwards to another web resource. If the resource is a JavaServer Page, then the container will render it, using its JSP engine. Likewise if the name attribute is not specified, the framework will give it the name "success". Using these intelligent defaults, the most often used result types also become the simplest.
-->
 <!--Result element without defaults-->

 <result name="success" type="dispatcher">
<param name="location">/ThankYou.jsp</param>
</result>
<!--A Result element using some defaults-->

<result>
<param name="location">/ThankYou.jsp</param>
</result>
 <!--Result element using more defaults-->

 <result>/ThankYou.jsp</result>
 <!--Multiple Results-->

 <action name="Hello">
<result>/hello/Result.jsp</result>
<result name="error">/hello/Error.jsp</result>
<result name="input">/hello/Input.jsp</result>
</action>
 <!--'*' Other Result-->

 <action name="Hello">
<result>/hello/Result.jsp</result>
<result name="error">/hello/Error.jsp</result>
<result name="input">/hello/Input.jsp</result>
<result name="*">/hello/Other.jsp</result>
</action> <!-- 名称= " * "不是一个通配符模式,它仅是一个特别的名字,如果没有找到完全匹配选择。 -->

Global Results

  Most often, results are nested with the action element. But some results apply to multiple actions. In a secure application, a client might try to access a page without being authorized, and many actions may need access to a "logon" result.

  If actions need to share results, a set of global results can be defined for each package. The framework will first look for a local result nested in the action. If a local match is not found, then the global results are checked.

 <!--Defining global results-->

 <global-results>
<result name="error">/Error.jsp</result>
<result name="invalid.token">/Error.jsp</result>
<result name="login" type="redirectAction">Logon!input</result>
</global-results>

Dynamic Results

  A result may not be known until execution time. Consider the implementation of a state-machine-based execution flow; the next state might depend on any combination of form input elements, session attributes, user roles, moon phase, etc. In other words, determining the next action, input page, etc. may not be known at configuration time.

  Result values may be retrieved from its corresponding Action implementation by using EL expressions that access the Action's properties, just like the Struts 2 tag libraries. So given the following Action fragment:

 //FragmentAction implementation

 private String nextAction;

 public String getNextAction() {
return nextAction;
}

you might define a result like this:

 <!--FragmentAction configuration-->

 <action name="fragment" class="FragmentAction">
<result name="next" type="redirectAction">${nextAction}</result>
</action> <!-- If a FragmentAction method returns "next" the actual value of that result will be whatever is in FragmentAction's nextAction property. So nextAction may be computed based on whatever state information necessary then passed at runtime to "next"'s redirectAction. -->

==============================================================

Result Types

Chain Result

Used for Action Chaining

Dispatcher Result

Used for web resource integration, including JSP integration

FreeMarker Result

Used for FreeMarker integration

HttpHeader Result

Used to control special HTTP behaviors

Redirect Result

Used to redirect to another URL (web resource)

Redirect Action Result

Used to redirect to another action mapping

Stream Result

Used to stream an InputStream back to the browser (usually for file downloads)

Velocity Result

Used for Velocity integration

XSL Result

Used for XML/XSLT integration

PlainText Result

Used to display the raw content of a particular page (i.e jsp, HTML)

Tiles 2 Result

Used to provide Tiles 2 integration

Tiles 3 Result

Used to provide Tiles 3 integration

Postback Result

Used to postback request parameters as a form to the specified destination

Parameters in configuration results

 <!--Parameters in action result definitions-->

 <struts>
...
<package name="somePackage" namespace="/myNamespace" extends="struts-default">
<action name="myAction" class="com.project.MyAction">
<result name="success" type="redirectAction">otherAction?id=${id}</result>
<result name="back" type="redirect">${redirectURL}</result>
</action> <action name="otherAction" class="com.project.MyOtherAction">
...
</action>
</package>
...
</struts>

  The only requirement is to declare the necessary properties in your action, in this case com.project.MyAction should define properties id and redirectURL with standard accessor methods.

 public class MyAction extends ActionSupport {
private int id;
private String redirectURL;
... public String execute() {
...
if (someCondition) {
this.redirectURL = "/the/target/page.action";
return "back";
} this.id = 123;
return SUCCESS;
} public int getId() { return this.id; }
public void setId(int id) { this.id = id; }
public String getRedirectURL() { return this.redirectURL; }
public void setRedirectURL(String redirectURL) { this.redirectURL= redirectURL; }
...
} /**
In the above code if it returns SUCCESS then the browser will be forwarded to
/<app-prefix>/myNamespace/otherAction.action?id=123
**/

Struts2.3.16日志(中)的更多相关文章

  1. [转]Struts2.3.16.1+Hibernate4.3.4+Spring4.0.2 框架整合

    原文地址:http://blog.csdn.net/ycb1689/article/details/22928519 最新版Struts2+Hibernate+Spring整合 目前为止三大框架最新版 ...

  2. struts2.3.16所需的基本的jar包---------SSH升级包不是整体全部都升级的

    struts2.3.16所需的基本的jar包   jar包放多了就报Exception什么Unable to load....上网搜了半天也没有能解决的 下面所说的jar包放到WEB-INF/lib以 ...

  3. 【J2EE】struts-2.3.16.3+apache-tomcat-8.0.9开发环境部署,“Hello World”的实现。

    1.在官网下载Struts2的开发包 下载链接如下: http://120.203.229.30/5ff/2bc79/5ff16ae8698e1c321758a8f03a1bc0939892bc79/ ...

  4. Nginx日志中的金矿 -- 好文收藏

    转:http://www.infoq.com/cn/articles/nignx-log-goldmine Nginx(读作Engine-X)是现在最流行的负载均衡和反向代理服务器之一.如果你是一名中 ...

  5. nginx日志中添加请求的response日志

    换个新公司,做一些新鲜的事情,经过一天的琢磨,终于成功添加response日志 在nginx的日志中添加接口response的日志 由于此功能在nginx内置的功能中没有,需要安装第三方模块ngx_l ...

  6. Kettle日志中BootFeaturesInstaller错误

    到新公司接手了别人的Kettle ETL作业. 发现每次启动 Kettle ,日志中都会出现下面的错误,虽然不影响运行结果,但是看着不爽: 18:41:15,327 INFO [KarafInstan ...

  7. linux服务端日志中截取自己所需要的部分

    近期开发一个图片处理的业务,涉及base64字符串解析的问题,为方便与友商间接口调试,日志中保存Base64.日,想想就肝儿疼,记录下来容易,取的时候难.为准确提取,配合两条命令即可. 1.获取日志所 ...

  8. Python统计日志中每个IP出现次数

    介绍了Python统计日志中每个IP出现次数的方法,实例分析了Python基于正则表达式解析日志文件的相关技巧,需要的朋友可以参考下 本脚本可用于多种日志类型 #-*- coding:utf-8 -* ...

  9. 在linux中使用shell来分析统计日志中的信息

    在运维工作中,要经常分析后台系统的日志,通过抓取日志中的关键字信息,对抓取结果进行统计,从而为监控结果提供基础数据.下面的shell演示了如何从大量的日志中取得想要的统计结果.其中展示了各种有趣的命令 ...

随机推荐

  1. Python logging模块使用记录

    1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...

  2. Android面试题集锦 (转)

    转自:http://xiechengfa.iteye.com/blog/1044721 一些常见的Android面试基础题做下总结,看看你能做出多少道? 1. Intent的几种有关Activity启 ...

  3. hdu_4529_郑厂长系列故事——N骑士问题(状压DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4529 题意:中文,不解释 题解:状压DP,dp[i][j][k][s]表示第i行当前用了j个骑士,i- ...

  4. IoC容器Autofac正篇之依赖注入(七)

    依赖注入,这个专业词我们可以分为两个部分来理解: 依赖,也就是UML中描述事物之间关系的依赖关系,依赖关系描述了事物A在某些情况下会使用到事物B,事物B的变化会影响到事物A: 注入,医生通过针头将药物 ...

  5. windows 装 centos

    windows下压缩一下空间 直接装centos 找到分配给linux的/boot目录,然后修改grub/menu.lst文件,更换一下位置即可

  6. webapp前端开发软键盘与position:fixed为我们带来的不便

    前提:我们考虑兼容的环境为android和ios两种智能手机 兼容环境测试结果显示android的表现明显好于ios,ios手机在软键盘呼起收起时存在着很严重的兼容性问题 场景展示: 页面正常状态 软 ...

  7. perl命令+关键字

    来源: http://www.cnblogs.com/itech/archive/2012/11/01/2749666.html http://www.garybeene.com/vb/tut-per ...

  8. JS-加载页面的时候自动选择刚才所选择option

    <body class="no-skin" onload="option_auto(${pd.PACK_SORT})"> <select na ...

  9. Mybatis 一对一,一对多,多对一,多对多的理解

    First (一对一) 首先我来说下一对一的理解,就是一个班主任只属于一个班级,一个班级也只能有一个班主任.好吧这就是对于一对一的理解 怎么来实现呢? 这里我介绍了两种方式: 一种是:使用嵌套结果映射 ...

  10. Shell命令替换与变量替换

    命令替换 命令替换是指Shell可以先执行命令,将输出结果暂时保存,在适当的地方输出.命令替换的语法: `command` 注意是反引号,不是单引号,这个键位于 Esc 键下方.下面的例子中,将命令执 ...