• Post Reply Bookmark Topic Watch Topic
  • New Topic

session management

 
Ravissant Markenday
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Amit Biswas
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • 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: 3830
  • Mark post as helpful
  • send pies
  • 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: 3830
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!