简体   繁体   English

从httpServletrequest和DWR httpServletrequest获取不同的会话

[英]Getting different sessions from httpServletrequest and DWR httpServletrequest

I am working on a legacy application, 我正在处理旧版应用程序,

where when the user logs in the request goes to filter and will be redirected to the home page after validation. 当用户登录时,请求将进行过滤,验证后将重定向到主页。 After that whenever user clicks on any link it will be verified whether user is an admin user using DWR. 之后,每当用户单击任何链接时,都将使用DWR验证用户是否为管理员用户。

The problem is we are getting different sessions when we fetch the session from 问题是,当我们从中获取会话时,我们获得了不同的会话

httpServletrequest.getSession(true);

and

WebContextFactory.get().getHttpServletRequest().getSession();

because of this when ever we try to get the user details from session we are getting null in the session what we are getting from DWR. 因此,无论何时我们尝试从会话中获取用户详细信息,我们在会话中得到的都是空,即从DWR获取的内容都是空的。

How to get same session which is created in httpServletrequest using DWR also. 如何也使用DWR获取在httpServletrequest中创建的相同会话。

According to this page : 根据此页面

WebContext is used when you are in a DWR thread. 在DWR线程中时使用WebContext。 It uses a ThreadLocal variable to connect you to the running container. 它使用ThreadLocal变量将您连接到正在运行的容器。

Are You in a DWR thread when You invoke WebContextFactory.get() ? 调用WebContextFactory.get()时是否在DWR线程中?

Alternatively You can include servlet objects in parameters list of Your remoted method object. 或者,您可以在远程方法对象的参数列表中包括servlet对象。

DWR will not include it on the generated stub and upon a call of the method it will fill it in automagically. DWR不会将其包含在生成的存根中,并且在调用该方法时,它将自动将其填充。

I did it like this and it worked. 我这样做是可行的。 I get the same session as in a standard request. 我得到的会话与标准请求中的会话相同。

public class Remote {
    public void method(int param, HttpSession httpSession) { ... }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM