struts的代码
- import javax.servlet.http.HttpServletRequest;
- import org.aopalliance.intercept.MethodInterceptor;
- import org.aopalliance.intercept.MethodInvocation;
- import org.apache.struts.action.ActionMapping;
-
-
-
-
-
- public class AuthorityInterceptor implements MethodInterceptor {
-
- public Object invoke(MethodInvocation invocation) throws Throwable
- {
- HttpServletRequest request = null;
- ActionMapping mapping = null;
- Object[] args = invocation.getArguments();
- for (int i = 0 ; i < args.length ; i++ )
- {
- if (args[i] instanceof HttpServletRequest) request = (HttpServletRequest)args[i];
- if (args[i] instanceof ActionMapping) mapping = (ActionMapping)args[i];
- }
- if ( request.getSession().getAttribute("adminname") != null)
- {
- return invocation.proceed();
- }
- else
- {
- return mapping.findForward("login");
- }
- }
- }
import javax.servlet.http.HttpServletRequest;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.struts.action.ActionMapping;
/**
* 这是一个拦截器,用来验证用户是否通过验证
*
*/
public class AuthorityInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable
{
HttpServletRequest request = null;
ActionMapping mapping = null;
Object[] args = invocation.getArguments();
for (int i = 0 ; i < args.length ; i++ )
{
if (args[i] instanceof HttpServletRequest) request = (HttpServletRequest)args[i];
if (args[i] instanceof ActionMapping) mapping = (ActionMapping)args[i];
}
if ( request.getSession().getAttribute("adminname") != null)
{
return invocation.proceed();
}
else
{
return mapping.findForward("login");
}
}
}
配置文件:
- <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
- <property name="beanNames">
- <list>
- <value>/vaiiduser</value>
- <value>/admin</value>
- <value>/phone</value>
- </list>
- </property>
- <property name="interceptorNames">
- <list>
- <value>authorityInterceptor</value>
- </list>
- </property>
- </bean>
-
- <bean id="authorityInterceptor" class="org.mmc.utils.AuthorityInterceptor"/>