Struts2 token interceptor in annotation

耗尽温柔 提交于 2020-01-04 04:40:12

问题


I'm using struts 2.3.1 with token interceptor.How can i use token interceptor in annotation(convension) based Action Class.

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.


回答1:


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;
  }
}


来源:https://stackoverflow.com/questions/14976471/struts2-token-interceptor-in-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!