• 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

Sharing session attributes between two servlets

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I understand that on saying response.sendRedirect(), a new request would be created (effectively, the previously existing request would be lost). But, will the existing session be still available thru request.getSession(false)?
The problem I am facing is:
1. I have two servlets running in my system, one for each application.
2. I want the values stored in the session to be shared between the two servlets (like When servlet1 redirects a particular request to servlet2).
3. Apart from composing a url with all the details needed by servlet2, I need certain other data to be taken from the session.
Is it possible?
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general, if you want to call a servlet from another, use a RequestDispatcher.
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Session attributes are only shared by servlets within the same web application (i.e. war). Beyond that, they are not shared. Further, you of course cannot forward to a servlet in another app--you must redirect.
 
Rhea Karnam
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, thanks for the info. Following this, if I return back to servlet 1 from servlet 2, will the values that I had stored in the session (before redirecting to servlet2) still be intact?
The scenrio is like this:
1. I store some values in the session , before redirecting to servlet2 from servlet1.
2. when servlet2 redirects back to servlet1, i want servlet1 to pick up the previously stored values and continue.
As it might be obvious, I am a beginner in this and not sure of my approach.
Rhea
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The values in the session will remain until one of the following happens:
1. They are explicity removed using session.removeAttribute().
2. The sessions expires due to client inactivity.
A session basically represents a conversation between a client (i.e the browser) and the server. Providing the user doesn't leave his desk for a long lunch break or sit looking at the same page for too long then the session will be retained on the server.
HTH
[ June 04, 2003: Message edited by: Andy Bowes ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic