Java – how to get HttpServletRequest in HttpSessionListener?
•
Java
How do I access request headers from sessionlistener?
I need to set a timeout when creating the current session The timeout needs to change according to the header in HttpServletRequest I already have a sessionlister (implementing httpsessionlister) to record the creation and destruction of new sessions. It seems to be the most reasonable place to set timeout
I tried the following, but it always sets CTX to null
FacesContext ctx = FacesContext.getCurrentInstance();
Solution
HttpSessionListener does not have access to the request because it is called to notify session destruction when there is no request
Therefore, filters or servlets are a better place to check requests and specify session timeouts
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码