struts拦截器

本文介绍了一个基于Spring Security的权限控制系统实现。通过自定义过滤器实现对特定Action的拦截,该过滤器打印开始和结束的日志信息。此方法适用于需要进行用户权限验证的Web应用。
spring-security模块实现了权限控制功能.

自定义过滤器
1.自定义一个类实现Interceptor接口.
2.配置在调用的action中.并且加入默认的过滤器栈.只要你要使用默认的过滤器栈.

<interceptors>
<interceptor name="auth" class="com.meiyoudao.filter.AuthFilter"></interceptor>
</interceptors>
<action name="welcome" class="com.meiyoudao.action.WelcomeAction">
<interceptor-ref name="auth"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result>/welcome.jsp</result>
</action>



/**
*
*/
package com.meiyoudao.filter;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
* @author meiyoudao
*
*/
public class AuthFilter implements Interceptor {

/* (non-Javadoc)
* @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see com.opensymphony.xwork2.interceptor.Interceptor#init()
*/
public void init() {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
*/
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("do something filter begin...");
String str = invocation.invoke();
System.out.println("do something filter end...");
return str;
}

}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值