`
bd_cool
  • 浏览: 60072 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

DWR请求中用过滤器验证session

    博客分类:
  • DWR
阅读更多

要解决dwr请求时,统一对session进行管理,在网上搜了一下,它有自己的过滤器,狂喜!

 

DwrFilter.java

 

public class DwrFilter implements AjaxFilter {
	private static final Log logger = LogFactory.getLog(DwrFilter.class);
	public Object doFilter(Object object, Method method, Object[] arr,
			AjaxFilterChain chain) throws Exception {
		
		//DWR方法session同步
		HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
		HttpSession session = request.getSession();
		SessionAgentTool.setSession(new SessionContext(session));
		
		//拦截调用方法
		String methodName = method.getName();
		logger.info("拦截DWR目标方法:" + methodName);

		Object obj = chain.doFilter(object, method, arr);
		logger.info("DWR目标方法 " + method.getName() + " 执行结束");
		return obj;
	}
}

 

dwr.xml添加以下代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" 
      "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
    <allow>
        ......
        <filter class="com.wingon.core.filter.DwrFilter"></filter>
    </allow>
</dwr>

 

 

就这两步,OK了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics