You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by De...@hydro.qc.ca on 2010/03/23 22:57:50 UTC

Loosing my HttpSession between Applet and Servlet

Hi,
 
I'am using HttpClient 4.0.1.
 
Each time my applet make a get or post to the servlet, I am loosing my httpSession on the back end.
 
How can we keep the httpSession alive with HttpClient ?
 
Here's the call that I made from my applet, each time it is call, i get a new httpSession from my servlet :
 
public static void getHttp(TestHttpSession applet) {

try {

HttpClient clientHttp = new DefaultHttpClient();

HttpResponse response = clientHttp.execute(httpGet);

HttpGet httpGet = new HttpGet(applet.getURL());

clientHttp.getConnectionManager().shutdown(); 

} catch (Exception e) {

e.printStackTrace();

}

}

Thanks,
Frank
 
 
François Deschamps
Conseiller en TI,
Centre d'expertise Java (DMDI)
Hydro-Québec
tel: 514-840-3000 (4756)
courriel: deschamps.francois.2@hydro.qc.ca <ma...@hydro.qc.ca> 
 

Re: Loosing my HttpSession between Applet and Servlet

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2010-03-23 at 17:57 -0400, Deschamps.Francois.2@hydro.qc.ca
wrote:
> Hi,
>  
> I'am using HttpClient 4.0.1.
>  
> Each time my applet make a get or post to the servlet, I am loosing my httpSession on the back end.
>  
> How can we keep the httpSession alive with HttpClient ?
>  
> Here's the call that I made from my applet, each time it is call, i get a new httpSession from my servlet :
>  
> public static void getHttp(TestHttpSession applet) {
> 
> try {
> 
> HttpClient clientHttp = new DefaultHttpClient();
> 
> HttpResponse response = clientHttp.execute(httpGet);
> 
> HttpGet httpGet = new HttpGet(applet.getURL());
> 
> clientHttp.getConnectionManager().shutdown(); 
> 
> } catch (Exception e) {
> 
> e.printStackTrace();
> 
> }
> 
> }
> 
> Thanks,
> Frank

No wonder the HTTP session does not stick, as you are creating a new
instance of HttpClient for each request. When HttpClient instance goes
out of scope, you lose all state information contained in it.

Oleg

>  
> 
> François Deschamps
> Conseiller en TI,
> Centre d'expertise Java (DMDI)
> Hydro-Québec
> tel: 514-840-3000 (4756)
> courriel: deschamps.francois.2@hydro.qc.ca <ma...@hydro.qc.ca> 
>  



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org