This is a client side issue. HTTP session supported by cookie. The client must ensure that it correctly sends the cookie to subsequent requests in accordance with the HTTP specification. The HttpClient API offers a class CookieStorethat needs to be set to HttpContext, which you, in turn, need to pass to each call HttpClient#execute().
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 work, read this answer: How do servlets work? Create, Sessions, Shared Variables, and Multithreading
source
share