aspose file tools*
The moose likes Servlets and the fly likes Client session state not tracked Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Client session state not tracked" Watch "Client session state not tracked" New topic
Author

Client session state not tracked

seema mani
Ranch Hand

Joined: Sep 30, 2001
Posts: 49
hi
I have a java client application which accesses a servlet by establishing a connection using URLConnection class. Now each time the doPost() of the servlet is called by the client, the servlet creates a new session. I want the servlet to reuse the same session it created the first time it was accessed. How can I make this happen? I tried fetching the session id, attached it to the url to enable url rewriting method of session tracking. But it is still not working. Please do advise.
Thanks in advance
Seema


Sun Certified Java Programmer<br />Sun Certified Web Component Developer<br />Sun Certified Business Component Developer
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
If your client wants to use URL-rewriting, then you have to make sure the server application supports it properly too, and many don't.
I suggest that a more robust solution is to use one of the many "web client" libraries which manage all the tedious stuff like cookies, headers, authentication and redirection for you.
My current favourite is HTTPUnit. It's described as a web site test system, but it contains some powerful and easy to use classes for just this sort of thing. If's free, and it can be found at http://httpunit.sourceforge.net/ .


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Your client is basically going to have to fake the operation of a browser with respect to recognizing and using cookie data in the http headers. If the client is creating the connection with a URL that starts "http://" then you are getting a HttpURLConnection so you have all of the HttpURLConnection and URLConnection methods to play with.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Client session state not tracked