How do I pick up the session cookie in my servlet?
Within the servlet it all depends on whether this is the first request of the session or a subsequent session. If it’s a subsequent session, then it’s easy; use HttpServletRequest.getCookies() or getHeaders(“cookie”). If it’s the first request, then there is some difficulty since the session has just been created and there’s no request cookie yet; in this case, use getId() to fetch the ID string. Unfortunately, unless you were able to do a getHeaders(“cookie”), you need to come up with the name of the session ID cookie since it’s not necessarily JSESSIONID as it is on Tomcat. The somewhat unsatisifactory way that I’ve found to get around this is to force the web server to always use JSESSIONID using some manual configuration. This has worked for me on WebSphere and iPlanet.