日期:2014-05-18  浏览次数:20839 次

java用代理判断session是否过期,过期后怎么跳转

package com.essp.uas.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public abstract class ProxyFactory<T> implements InvocationHandler {

private T target;

public ProxyFactory(T target) {
super();
this.target = target;
}

public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Object o = null;
try {
before(args);
o = method.invoke(target,args);
after(method.getName(),args);
} catch (Exception e) {
onException(e);
e.printStackTrace();
}
return o;
}

@SuppressWarnings("unchecked")
public T createProxy() {
Class<T> cls = (Class<T>) target.getClass();
if (cls.getInterfaces() != null)
return (T) Proxy.newProxyInstance(cls.getClassLoader(), cls
.getInterfaces(), this);
return target;
}

public abstract void onException(Exception ex);

public abstract void before(Object[] args);

public abstract void after(String methodName,Object[] args);
}



这是我的代码,我的想法是在before方法中判断session是否过期,如果过期想在页面上弹出一个alert提示框。after是用来记录操作日志的。
我想请教如果session失效,怎么在页面上弹出一个alert提示?

------解决方案--------------------
在request里面添加一个值,该值记录后台检查的session状态。
前台页面JS检测下,如果不为空就弹出alert,为空就不跳了
------解决方案--------------------
引用:
Quote: 引用:

在request里面添加一个值,该值记录后台检查的session状态。
前台页面JS检测下,如果不为空就弹出alert,为空就不跳了

我想在before中就跳转到登录页面可以吗?不知道怎么跳转


要跳转页面要用filter或servlet。