本action演示了一个action执行完成后,转到另外一个action的情况。
(1)如果需要内部转发:则在要转到的方法前面定义一个新的action名称,名称为:前一方法名!前一方法返回值.
(2)如果需要外部重定向:则定义一个Result,类型必须为"redirect"。
(3)若即定义了外部重定向Result,也定义了内部转发,显调用时的名称相同,则执行外部重定向Result
package com.abc.domain.access.action.common;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
@Controller
@Scope("prototype")
//声明此类为控制层的类,且为prototype模式调用
@ParentPackage(value = "abc-default")
@Results(
{
@Result(name="toShow", location="show.action", type="redirect"),
@Result(name="add", location="add.action", type="redirect")
})
@Namespace("/common/test")
public class TestAction
{
@Actions({
@Action("show"),
@Action("one!show")
})
public String show() throws Exception
{
return "success";
}
@Actions({
@Action("add"),
@Action("two!add")
})
public String add() throws Exception
{
return "success";
}
@Action("one")
public String one() throws Exception
{
//return "show"; //内部转发到show(),找到名为"one!show"的Action执行
return "toShow"; //外部重定向到show(),找到名为"toShow"的Result,然后再执行show()
}
@Action("two")
public String two() throws Exception
{
return "add"; //外部重定向到add(),因为找到了名称为add的Result配置,所以不再去找two!add
}
}
分享到:
相关推荐
struts2的convention配置详解 很全
简述STRUTS2_Convention零配置
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
从struts2.1版本开始,Convention Plugin作为替换替换Codebehind Plugin来实现Struts2的零配置。 • 包命名习惯来指定Action位置 • 命名习惯制定结果(支持JSP,FreeMarker等)路径 • 类名到URL的约定转换 • 包名...
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
struts2采用convention-plugin实现零配置,讲述如何不通过配置文件搭建struts2
struts2-convention-plugin-2.3.15.1.jar
Struts2插件convention
struts2-convention-plugin-2.3.32
无需配置Convention即可使用Convention,Convention的某些约束习惯可以通过配置属性来控制,您也可以在类中覆写其中的方法来达到扩展目地。
从struts2.1版本开始,Convention Plugin作为替换替换Codebehind Plugin来实现Struts2的零配置。
struts2-convention-plugin-2.3.24.1
struts2-convention-plugin-2.3.15.3.jar struts2配置Action注解要用到的包,真正实现零配置
Struts2_Convention_Plugin中文文档
默认包路径包含action,actions,struts,struts2的所有包都会被struts作为含有Action类的路径来搜索。你可以通过设置struts.convention.package.locators属性来修改这个配置。如: <constant name="struts.convention....
如何使用插件convention来实现struts2框架的零配置以及整合ssh架构
在Struts2如何使用Tiles JSON jQuery Convention的网上资料收集包。