注释中的 Struts2 令牌拦截器
问题描述:
我正在使用带有令牌拦截器的 struts 2.3.1.如何在基于注释(转换)的操作类中使用令牌拦截器.
I'm using struts 2.3.1 with token interceptor.How can i use token interceptor in annotation(convension) based Action Class.
这里是我的 struts.xml
here is My struts.xml
<action name="tokenAction" class="roseindia.action.TokenAction">
<interceptor-ref name="token" />
<interceptor-ref name="basicStack"/>
<result name="success" >/success.jsp</result>
<result name="invalid.token">/index.jsp</result>
任何人都可以告诉基于相同的注释.
can any one please tell annotation based for the same.
答
在我看来,这在文档 这里,你需要这样做:
It looks to me like this is fairly clear in the documentation here, you need to do this:
package com.example.actions;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
@InterceptorRefs({
@InterceptorRef("token"),
@InterceptorRef("basicStack")
})
@Results({
@Result(name="success", location="/success.jsp")
@Result(name="invalid.token", location="/index.jsp")
})
public class HelloWorld extends ActionSupport {
@Action(interceptorRefs={
@InterceptorRef("token"),
@InterceptorRef("basicStack")
})
public String myActionMethod() {
//do stuff
return SUCCESS;
}
}