要解决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了。