FacesContext and HttpSession in Servlets
Hi,
I'm using a servlet in my jsf-based application to retrieve some data via an xml request.
The FacesContext is set in the servlet as proposed in http://www.thoughtsabout.net/blog/archives/000033.html.
I have some important parameters set in the http session so when getting the servlet context I do:
servletContext = ((HttpServletRequest)request).getSession(false).getServletContext();
The problem is thatsometimes ((HttpServletRequest)request).getSession(false) returns null. I can't recreate the session because I will lose all parameters set.
Can anybody tell me why is the http session lost or why does it become irrecovarable?
Thanks
[734 byte] By [
Kremenaa] at [2007-11-27 5:02:29]

# 1
If request.getSession(false) returns null, there is no danger in creating a session as there is no longer any any session to lose.
I suspect that really won't solve your problem however. I think the real problem you are having is that sometimes the existing session is not preserved for some requests. Some things to think about if that is the case:
- are you switching between https and http?
- does the client support cookies?
- are you creating all links via HttpResponse.encodeUrl()
- has the server been restarted or the application been redeployed?
- has the session timed out?
# 2
Hi,
I have the same problem. I create the facesContext in my servlet. Then forward to another webapplication. The other app forwards back to another servlet of my app. When i test on my development machine everything works fine. When i deploy the app, sometimes my session is gone. My previous version was not creating the FacesContext in the servlet and was working fine. I had some extra parameters to handle, so i thought it was better to create the facesContext already in the servlet. But since then i have the problem. Kremena did you already found what is causing the problem? I hope somebody can help me fast with this.
Greetz