This is a problem in the client side. The HTTP session is maintained by a cookie. The client needs to ensure that it properly sends the cookie back on the subsequent requests as per the HTTP spec. The HttpClient API offers the CookieStore
class for this which you need to set in the HttpContext
which you in turn need to pass on every HttpClient#execute()
call.
HttpClient httpClient = new DefaultHttpClient();
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
// ...
HttpResponse response1 = httpClient.execute(yourMethod1, httpContext);
// ...
HttpResponse response2 = httpClient.execute(yourMethod2, httpContext);
// ...
To learn more about how sessions works, read this answer: How do servlets work? Instantiation, sessions, shared variables and multithreading