1.新建一个拦截器(Interceptor)
package cn.devon.interceptor;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class LoginInterceptor extends AbstractInterceptor {
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext ctx= invocation.getInvocationContext();
//如果未登陆,则跳转到登陆页面
if( null == ctx.getSession().get("L_Member")){
return "loginPage";
}else
return invocation.invoke();
}
}
2.配置struts.xml,设置拦截器作用范围(此处作用于“adminModul package中所有的action”)
<package name="adminModul" extends="struts-default" namespace="/admin">
<interceptors>
<interceptor name="loginInterceptor" class="cn.devon.interceptor.LoginInterceptor"/>
</interceptors>
<default-interceptor-ref name="loginInterceptor"/>
<global-results><!-- 配置全局返回页面 -->
<result name="loginPage" type="redirect">/login.jsp</result>
</global-results>
<action name="articles" class="articleAction" method="list">
<result name="success">adminArtilceList.jsp</result>
<result name="error">error.jsp</result>
</action>
...
</package>
分享到:
相关推荐
详细介绍struts2 interceptor
Struts2拦截器(Interceptor) Struts2拦截器(Interceptor)
NULL 博文链接:https://weizhilizhiwei.iteye.com/blog/1005210
struts2 Interceptor拦截器 http://whitewolf.0fees.net
Struts2_interceptor_和_filter区别
STRUTS2:拦截器Interceptor
综合使用servlet filter与struts2 interceptor对权限进行验证。
简单的拦截器例子,适合初学者学习,也是一个备忘录
用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)
Struts2拦截器是在访问某个Action或Action的某个方法,字段之前或之后实施拦截,并且Struts2拦截器是可插拔的,拦截器是AOP的一种实现.
struts1 拦截器功能的实现。struts2 中的interceptor很方便。但在struts1中没有这个功能,用这个插件很容易实现。
ssh2-interceptor拦截器(权限管理).
Struts2.x_Interceptor已经打包好了,解压后直接用,
利用Struts2的核心技术----拦截器实现权限控制。详细代码详解
Struts2.3.6实现自定义拦截器Interceptor http://blog.csdn.net/alanchen520/article/details/34086699
struts2 拦截器_教程.zip
Interceptor,学习Struts 2实例,一步步教你如何实现一个示例
《Struts 2实战》结合实例介绍了Struts 2框架,主要内容包括Action、Result、Interceptor等框架组件,基于注解的配置选项等新特征,Struts 2插件 FreeMarker,如何从Struts 1和WebWork 2迁移到Struts 2,Ajax标签、...
struts2,Interceptor struts2拦截器实例,两套实例,一套是针对单个的action配置的,另一套实例是针对全局的action配置的拦截器interceptor
struts2 interceptor 的一个简单的 登录系统小demo