app-context.xml中添加一个Ajax交互的拦截器:
<bean parent="dorado.viewServiceInterceptorRegister"> <property name="methodInterceptor"> <bean class="com.xxx.xxx.system.common.UserSessionViewServiceInterceptor" /> </property> </bean>
java参考代码:
package com.xxx.xxx.system.common; import javax.servlet.http.HttpServletRequest; import org.aopalliance.intercept.MethodInvocation; import com.bstek.dorado.view.resolver.ClientRunnableException; import com.bstek.dorado.view.service.AbstractRemoteServiceMethodInterceptor; import com.bstek.dorado.web.DoradoContext; public class UserSessionViewServiceInterceptor extends AbstractRemoteServiceMethodInterceptor { @Override protected Object invoke(MethodInvocation invocation, String serviceName) throws Throwable { HttpServletRequest request = DoradoContext.getCurrent().getRequest(); Object user = request.getSession().getAttribute("userObject"); if (null==user){ throw new ClientRunnableException("Session超时","window.top.location.href='./index.html';"); } Object object = invocation.proceed();//调用默认的ajax服务 return object; } }
其中ClientRunnableException的第二个参数可以设置为一段script脚本,最终这段脚本在客户端会被eval()函数执行,便于你做重新登录或跳转到登录页面之类的相关操作。