日期:2014-05-19  浏览次数:20757 次

struct中@Result注解的问题

@Controller
@Scope("prototype")
@Results( {  
 @Result(type=ServletRedirectResult.class, value = "/default.jsp"),
@Result(name = "input", value = "loginError.jsp") 
})
public class LoginAction extends ActionSupport {
}


以上的代码,注解@Controller我知道是给spring管理的
                @Scope("prototype")
                 是从bean工厂所取得的实例为Singleton(bean的singleton属性) Singleton: Spring容器只存在一个共享的bean实例,默认的配置。 Prototype: 每次对bean的请求都会创建一个新的bean实例。二者选择的原则:有状态的bean都使用Prototype作用域,而对无状态的bean则应该使用singleton作用域。

怎么样去理解下面的注解,我思考了许久,还是没有头绪,请各位,帮我解析解析,谢谢大家!
                @Results( {  
 @Result(type=ServletRedirectResult.class, value = "/default.jsp"),
@Result(name = "input", value = "loginError.jsp") 
})  

------解决方案--------------------
@Result(type=ServletRedirectResult.class, value = "/default.jsp"),
 意思是:<result name="success" tyle="redirect">/default.jsp</result>

@Result(name = "input", value = "loginError.jsp") 
 意思是:<result name="input">/loginError.jsp</result>

我翻译的是 struts2的配置文件写的写法。。。这个你看不懂的话。。那我没话说
------解决方案--------------------
在每个方法上面配置@Action注解就行,这个注解里面可以指定action的名称
------解决方案--------------------
 如果你要使用注解的话你必须在action里面的每个方法上都加一个@action ,这就不能像用xml那样使用通配符来动态指定调用方法. 我个人觉得还是用xml配置文件的方式来配置比较灵活.