1,interceptor原理,执行过程
2,创建一个interceptor,实现interceptor接口
3.重写三个方法: init()
destroy()
intercept(ActionInvocation arg0)
4.struts.xml文件中进行配置例如:
<struts>
<package name="struts" extends="struts-default">
<interceptors>
<interceptor name="proInterceptor" class="com.softeem.action.ProIntercept"></interceptor>
<interceptor-stack name="roleIntercept">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="proInterceptor"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="loginAction" class="com.softeem.action.LoginAction">
<result type="chain">managerAction</result>
</action>
<action name="managerAction" class="com.softeem.action.ManageAction">
<interceptor-ref name="roleIntercept"></interceptor-ref>
<result>/success.jsp</result>
</action>
</package>
</struts>
2,创建一个interceptor,实现interceptor接口
3.重写三个方法: init()
destroy()
intercept(ActionInvocation arg0)
4.struts.xml文件中进行配置例如:
<struts>
<package name="struts" extends="struts-default">
<interceptors>
<interceptor name="proInterceptor" class="com.softeem.action.ProIntercept"></interceptor>
<interceptor-stack name="roleIntercept">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="proInterceptor"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="loginAction" class="com.softeem.action.LoginAction">
<result type="chain">managerAction</result>
</action>
<action name="managerAction" class="com.softeem.action.ManageAction">
<interceptor-ref name="roleIntercept"></interceptor-ref>
<result>/success.jsp</result>
</action>
</package>
</struts>
本文详细介绍了Struts框架中拦截器(Interceptor)的工作原理及执行流程,并提供了创建自定义拦截器的具体步骤,包括实现Interceptor接口并重写init、destroy及intercept方法。此外,还展示了如何在struts.xml配置文件中定义和使用拦截器。
301

被折叠的 条评论
为什么被折叠?



