在web.xml里的DWR配置中加入一个参数:
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>
org.directwebremoting.extend.Remoter
</param-name>
<param-value>com.xxx.base.framework.web.MyDWRRemoter</param-value>
</init-param>
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
org.directwebremoting.extend.ServerLoadMonitor
org.directwebremoting.impl.PollingServerLoadMonitor
<body οnlοad="dwr.engine.setActiveReverseAjax(true)">
import org.directwebremoting.Browser;
import org.directwebremoting.ScriptSessions;
public class MyDWRRemoter extends DefaultRemoter
{
public Replies execute( Calls calls )
{
HttpSession session = WebContextFactory.get().getSession();
ISessionContainer sc = ( ISessionContainer ) session.getAttribute( ISessionContainer.SESSION_CONTAINER_KEY );
//session检查
if ( sc == null || sc.getUserInfo() == null )
{
logOut();
return super.execute( new Calls() );
}
else
{
IUserInfo userInfo = sc.getUserInfo();
if(!SecurityFactory.getInstance().isOnline( userInfo.getUserID(), session.getId() ))
{
logOut();
return super.execute( new Calls() );
}
}
return super.execute( calls );
}
private void logOut()
{
WebContext wct = WebContextFactory.get();
Util utilThis = new Util(wct.getScriptSession());
utilThis.addScript( new ScriptBuffer("logOut()"));
}
}