Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Client session state not tracked

 
seema mani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/ .
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic