struts2 — interceptor(如何配置Interceptor)成功运行过
时间:2021-12-14 作者:匿名
struts2 配置
<package name="admin" extends="struts-default" namespace="/"> <interceptors> <interceptor name="loginInterceptor" class="域名域名nInterceptor" /> <interceptor-stack name="checkStack"> <interceptor-ref name="loginInterceptor" /> <interceptor-ref name="defaultStack" /> </interceptor-stack> </interceptors> <action name="user" class="域名域名Action"> <result name="main">域名</result> <result name="list">域名</result> <result name="update_list">域名</result> <result name="input">域名</result> <interceptor-ref name="checkStack"></interceptor-ref> </action> </package>
自定义拦截器
package 域名rceptor; import 域名域名onInvocation; import 域名域名rceptor; import 域名域名Action; public class LoginInterceptor implements Interceptor{ @Override public void destroy() { // TODO Auto-generated method stub } @Override public void init() { // TODO Auto-generated method stub } @Override public String intercept(ActionInvocation invocation) throws Exception { 域名tln("进入拦截器"); // 对LoginAction不做该项拦截 Object action = 域名ction(); if (action instanceof UserAction) { 域名tln("exit check login, because this is login action."); return 域名ke(); } return 域名ke(); } }
附上官方文档
http://域名/docs/域名?
http://域名/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-域名(这里写怎么配置的例子)