利用spring拦截struts(1.x)中的action
在struts-config.xml中配置:
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>
新建AuthMethodInteceptor:
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.struts.action.ActionMapping;
import entity.Users;
public class AuthMethodInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable {
Object[] object=invocation.getArguments();
try
{
HttpServletRequest request = (HttpServletRequest) invocation.getArguments()[2];
ActionMapping mapping=(ActionMapping) invocation.getArguments()[0];
Users user = (Users) (request.getSession().getAttribute("user"));
if(user==null)
{
return mapping.findForward("login");
}
Object returnObject = invocation.proceed();
return returnObject;
}
catch(Exception e)
{
}
return object;
}
}
spring配置文件中:
<bean id="authInterceptor" class="utils.AuthMethodInterceptor">
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list>
<value>authInterceptor</value>
</list>
</property>
<property name="beanNames">
<list>
<value>/*insert</value>
</list>
</property>
</bean>
测试了下,好像用不了,什么原因?