Dwr WebContextFactory.get() null 问题

由于项目是用DWR3 + SPRING + EXTJS 组建,所以有些地方用到了SERVLET,用户登录成功后就将用户的信息放在SESSION中,在其它地方直接用WebContextFactory.get().getSession().getAttribute("USER");来获取当前用户信息。只有一个SERVLET时,没有问题,但是当一个同事为了下载功能又写了一个SERVLET。问题出现了!即用WebContextFactory.get().getSession().getAttribute("USER");会直接报错,NULL类型错误。

查了半天,个人理解应该是每个SERVLET会产生不同的上下文,,但是DWR的WebContextFactory.get()并不能自动增加另一下上下文。

查了DWR3的源码,WebContextFactory.get()是WebContextBuilder提供的,于是想直接通过创建WebContextBuilder来完成这两个SERVLET的联系。代码如下:

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServerContext sc = ServerContextFactory.get();// DWR的上下文 WebContextBuilder webBuilder = new DefaultWebContextBuilder();// 创建WebContextBuilder webBuilder.engageThread(sc.getContainer(), request, response);// Make the current thread know what the current request is

……

}

不做任何解释。没有人明白,

Dwr WebContextFactory.get() null 问题

相关文章:

你感兴趣的文章:

标签云: