Struts 2入門-インターセプタ(interceptor) の使い方
1.Interceptorの実装
public class DemoInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
//some code
return invocation.invoke();
}
}
2.Interceptorを登録する
struts.xml
<struts>
<package name="demo-package" abstract="true" extends="json-default">
<interceptors>
<interceptor name="demo"
class="com.ctn.DemoInterceptor"></interceptor>
</interceptors>
<!– interceptor stack Definitions –>
<interceptor-stack name="testStack">
<interceptor-ref name="basicStack" />
<interceptor-ref name="test" />
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<interceptor-ref name="jsonValidation" />
<interceptor-ref name="workflow" />
</interceptor-stack>
</package>
</struts>
3.Interceptorを利用する
@Namespace(“/")
@ParentPackage(“demo-package")
public class DemoDisplayAction extends ActionSupport {
//some code
}