@Action
使用属性将本地结果配置为操作配置。换句话说,本地结果是在允许的地方配置的。使用@Action
注释可以指定属性results
列表。您可以在此处添加@Result
注释。
Dave Newton 的书“Apache Struts 2 Web Application Development”有一段摘录:
我们还可以使用 Convention 的注释来配置结果。我们不必依赖 Convention 插件对我们的结果 JSP 文件应该命名的想法。@Result
我们可以使用注释手动定义结果
,@Results
如果我们需要多个结果,可以使用注释。(我们@Results
只能在类级别使用注解,而@Action
and@Actions
注解在方法级别可用。我们可以通过注解的属性在动作级别定义多个结果@Action
results
。 )
维基定义也正确
全局结果在动作类中定义的所有动作之间共享。这些结果被定义为动作类的注释。本地结果仅适用于定义它们的操作方法。以下是不同类型的结果注释的示例:
com.example.actions.HelloWorld
package com.example.actions;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
@Results({
@Result(name="failure", location="fail.jsp")
})
public class HelloWorld extends ActionSupport {
@Action(value="/different/url",
results={@Result(name="success", location="http://struts.apache.org", type="redirect")}
)
public String execute() {
return SUCCESS;
}
@Action("/another/url")
public String doSomething() {
return SUCCESS;
}
}