参考:

http://struts.apache.org/2.0.11/docs/result-annotation.html

http://jdkcn.com/entry/add-params-to-struts2-result-annotation.html

在原来的webwork式的xml配置文件里可以给<action>下的<result>节点添加一些额外的参数。
<result ..>
      <param name="">...</param>
</result>
那换成@Result annotation之后要怎么做呢。

看@Result的源代码发现有个params的String数组

@Retention(RetentionPolicy.RUNTIME)
public @interface Result {
    String name() default Action.SUCCESS;
    Class type() default NullResult.class;
    String value();
    String[] params() default {};
}

可是原来的param配置是个key和value的键值对啊。后来查到struts2的文档原来就这个String数组里约定的是key,value,这样的顺序。

  • params - An Array of the parameters in the form {key1, value1, key2, value2}

@Result(name="error",type=FreemarkerResult.class, value="/error.ftl", params={"contentType", "application/xml"})

传参数呢?

@Result(name="success",
  type="redirectAction",
  location="d-list",
  params={"id", "%{id}""}
)

这样,当return SUCCESS时,就会跳转至d-list?id=XXXX

struts2的@Result annotation 如何添加params的更多相关文章

  1. struts2的@Result annotation 如何添加params,并且在页面取值

    http://www.bubuko.com/infodetail-2492575.html .............................................. 标签:lai  ...

  2. Struts2 配置文件result的name属性和type属性

    Struts2 配置文件result的name属性和type属性:Name属性SUCCESS:Action正确的执行完成,返回相应的视图,success是 name属性的默认值: NONE:表示Act ...

  3. Struts2 自定义Result

    注意:我只要是解决自定义返回Json 和异常处理问题 新建一个类 AjaxResult   继承 StrutsResultSupport 看看代码吧 public class AjaxResult e ...

  4. Struts2中基于Annotation的细粒度权限控制

    Struts2中基于Annotation的细粒度权限控制 2009-10-19 14:25:53|  分类: Struts2 |  标签: |字号大中小 订阅     权限控制是保护系统安全运行很重要 ...

  5. Struts2之Result详解

    上一篇我们把Struts2中的Action接收参数的内容为大家介绍了,本篇我们就一起来简单学习一下Action的4种Result type类型,分为:dispatcher(服务端页面跳转):redir ...

  6. Caused by: The Result type [json] which is defined in the Result annotation on the class

    1.错误描述 严重: Dispatcher initialization failed Unable to load configuration. - [unknown location] at co ...

  7. struts2的result的类型配置简介

    一.在strut2的action处理完成后,就应该向用户返回结果信息result 根据以下代码作为实例分析: <package name="Hello" extends=&q ...

  8. Struts2 中result type属性说明

    Struts2 中result type属性说明 首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-t ...

  9. struts2 action result type类型

    struts2 action result type类型 1.chain:用来处理Action链,被跳转的action中仍能获取上个页面的值,如request信息. com.opensymphony. ...

随机推荐

  1. 20145120 《Java程序设计》实验一实验报告

    20145120 <Java程序设计>实验一实验报告 实验名称:Java开发环境的熟悉 实验目的与要求: 1.使用JDK编译.运行简单的Java程序:(第1周学习总结) 2.编辑.编译.运 ...

  2. Quartz 2D画虚线-b

    这里使用的函数为 CGContextSetLineDash,有四个参数    CGContextSetLineDash(<#CGContextRef  _Nullable c#>, < ...

  3. 小杜同学关于Query的一点知识

    小杜同学关于jQuery的一点知识 1.关于jQuery jQuery就是一个JavaScript的函数库.既然是JS的的函数库,它自然是做JS做的东西了.毕竟jQuery只是用JavaScript编 ...

  4. 2463: [中山市选2009]谁能赢呢?- BZOJ

    Description小明和小红经常玩一个博弈游戏.给定一个n×n的棋盘,一个石头被放在棋盘的左上角.他们轮流移动石头.每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的格子之 ...

  5. ASP.NET MVC 4 插件化架构简单实现-实例篇

    先回顾一下上篇决定的做法: 1.定义程序集搜索目录(临时目录). 2.将要使用的各种程序集(插件)复制到该目录. 3.加载临时目录中的程序集. 4.定义模板引擎的搜索路径. 5.在模板引擎的查找页面方 ...

  6. C++ 面试题整理

    我和朋友们面到的c++试题整理 虚表 static const sizeof 可构造不可继承的类 stl Iterator失效 map vector vector的removed_if 优化 ---- ...

  7. [设计模式] 8 组合模式 Composite

    DP书上给出的定义:将对象组合成树形结构以表示“部分-整体”的层次结构.组合使得用户对单个对象和组合对象的使用具有一致性.注意两个字“树形”.这种树形结构在现实生活中随处可见,比如一个集团公司,它有一 ...

  8. uva 434

    贪心 ~ #include <cstdio> #include <cstdlib> #include <cmath> #include <map> #i ...

  9. Kafka之Purgatory Redesign Proposal (翻译)

    Purgatory是Kafka server中处理请求时使用的一个重要的数据结构.正好研究ReplicaManager源码的时候发现了这篇文章,顺便翻译下.由于这个proposal里的很多东西需要看源 ...

  10. A const field of a reference type other than string can only be initialized with null Error [duplicate]

    I'm trying to create a 2D array to store some values that don't change like this. const int[,] hiveI ...