日期:2014-05-20  浏览次数:20720 次

struts2 如何拦截jsp 请求
拦截器可以在action 被执行前 就可以做加载动作。
拦截器 能在jsp显示页面被请求前就执行加载么?
应该放在哪里呢。


------解决方案--------------------
public class LoginInterceptor extends AbstractInterceptor {

@Override
public String intercept(ActionInvocation invocation) throws Exception {

//判断用户是否登录
if(invocation.getInvocationContext().getSession().get("user") !=null){
//如果登录,释放控制权
return invocation.invoke();
}else{
//未登录,返回到登录页面
return Action.LOGIN;
}

}


Struts.xml中注册

<interceptor name="loginInterceprot" class="com.wq.interceptor.LoginInterceptor"></interceptor>