• 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

session management

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone!

im doing sessions and could use help with a simple doubt. I want 2 servlets A and B to interact, A sends some data to B. Then in which servlet do i need to create the HttpSession object?

thanks in advance,
Ravissant
 
Ravissant Markenday
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone !

Ok now to put my last question a bit more clearly, does a seperate session object need to be created for each and every servlet, or can one HttpSession object be used for more than one servlets?
would really appreciate some help on this one.
Thanks in advance,

Ravissant Markenday
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the Servlet code, you will get a reference of the request object, from where you need to retrieve the session. For interactions between the servlets, use the servlet config object, that you can get from the GenericServlet code itself.
 
Ravissant Markenday
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Amit.
As i mentioned in my second message I also want to know -does a seperate session object need to be created for each and every servlet, or can one HttpSession object be used for more than one servlets?

Thanks again,

Regards,
Ravissant Markenday
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you writing a web server yourself, or are you using an existing web server? In general a web server will create a Session for you, and you needn't (and shouldn't) do it yourself - unless you are writing the web server itself. And if that's the case, you'll probably need to know a lot more than this little detail. Generally though, a web server will create a new Session only when there's a need for it. If there's an already-existing session that hasn't timed out or otherwise been invalidated, it will re-use the existing session. Even across different servlets.
 
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

can one HttpSession object be used for more than one servlets


The session concept is closely tied to the idea of "web applications" - one web application can have many servlets which will all share the same servlet context and HttpSession. This is all covered in the servlet API.
Anybody doing servlet or JSP coding should have a copy of the API, which you can download from here.
The API is designed so that multiple "web applications" can be hosted in a single server without interference or security problems.
Bill
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ravissant Markenday:
hi everyone!

im doing sessions and could use help with a simple doubt. I want 2 servlets A and B to interact, A sends some data to B. Then in which servlet do i need to create the HttpSession object?

thanks in advance,
Ravissant



No, a request object will suffice the purpose.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ravissant Markenday:
hi everyone !

Ok now to put my last question a bit more clearly, does a seperate session object need to be created for each and every servlet, or can one HttpSession object be used for more than one servlets?
would really appreciate some help on this one.
Thanks in advance,

Ravissant Markenday



session corresponds to user and not to servlet so one session for each user irrespective of number of servlets.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amit Biswas:
For interactions between the servlets, use the servlet config object, that you can get from the GenericServlet code itself.



servlet config is not to intract b/w the servlets, it's for single servlet and it's parameters are configured in web.xml and doesn't have attributes.
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic