我创建了一个 DWR ajaxfilter,但不确定如何使用 Spring 对其进行配置。DWR 版本是 2.0.1,我希望将其配置为全局过滤器,因此当会话过期时,我可以在客户端捕获此异常。
包 com.gbtags;
导入 org.directwebremoting.AjaxFilter;导入 org.directwebremoting.AjaxFilterChain;导入 org.directwebremoting.WebContextFactory;导入 org.directwebremoting.extend.LoginRequiredException;
导入java.lang.reflect.Method;
public class DWRSessionFilter 实现 AjaxFilter { public Object doFilter(Object obj, Method method, Object[] params, AjaxFilterChain chain) throws Exception {
//Check if session has timedout/invalidated
if( WebContextFactory.get().getSession( false ) == null ) {
System.out.println("session expired");
//Throw an exception
throw new LoginRequiredException( "This operation requires login." );
}
return chain.doFilter(obj, method, params);
}
}