• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Client session state not tracked

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/ .
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic