DWR2.0的调用前拦截

< init-param >
            
< param-name >
                org.directwebremoting.extend.Remoter
            
</ param-name >
            
< param-value > com.xxx.base.framework.web.MyDWRRemoter </ param-value >
        
</ init-param >

然后自己创建这个实现类。
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() " ));
    }

}

其中,检查用户是否登录,如果没有登录就返回一个空的super.execute( new Calls());, 不能返回null否则会报错。
检查通过就调用super.execute( calls );  其实calls里还能获得很多信息。

最后大家注意logOut方法,这里用到了DWR2.0新功能:DWR反向调用,就是DWR调用javascript,具体用法大家网上可以查到,需要配置的,我这里就不多说了。补充一下,addScript调用的是html里的function logOut().

这样的话,如果用户session超时,或被管理员踢掉,一旦他做任何dwr操作就会被强迫登出到首页了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值