如何在sessionDestroyed方法中获取请求对象? [英] How to get request object in sessionDestroyed method?
问题描述
我需要在 sessionDestroyed
方法中的Request对象,因为我需要检索Cookie。
I am in need of Request object in sessionDestroyed
method because I need to retrieve Cookies there.
public void sessionDestroyed(HttpSessionEvent httpSessionEvent)
{
// Here I need to get Request object so that I can retrieve Cookies.
}
是否可以获得请求
object,以便我可以检索Cookie?
Is it possible to get request
object so that I can retrieve Cookies there?
推荐答案
当会话被销毁时,不一定有HTTP请求的手段。它可以在超时期间被销毁,因为客户端没有发送任何请求。 30分钟。 HTTP请求将可用的唯一情况是,当您显式调用 HttpSession#invalidate()
时,按下注销按钮。但是当你调用该方法时,你已经有一个HTTP请求在你的手。
No. There is not necessarily means of a HTTP request when the session is been destroyed. It can namely be destroyed during a timeout because the client hasn't sent any request for e.g. 30 minutes. The only case that a HTTP request would be available, is the case when you explicitly invoke HttpSession#invalidate()
yourself when e.g. a logout button is been pressed. But at the moment when you invoke that method, you would already have a HTTP request at your hands. You could then just do the cookie job at the same moment instead of in a session listener.
你不清楚具体的功能要求,你错误地认为,这将是正确的解决方案,所以我不能给出一个非常适合的答案如何正确地解决。但是其中一种方法是将存储在cookie中的信息的副本存储为会话的属性。如果你需要在每个请求的基础上做,因为cookie值可以由JS在客户端操纵,例如,那么你可以使用 servlet过滤器。
You're not clear on the concrete functional requirement for which you incorrectly thought that this would be the right solution, so I can't give a well suited answer as to how to solve that properly. But one of the ways would be to just store a copy of the information stored in the cookie as an attribute of the session. If you need to do that on a per-request basis, because the cookie value could be manipulated by JS in the client side, for example, then you could use a servlet filter for this.
这篇关于如何在sessionDestroyed方法中获取请求对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!