• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the Difference B/W Setting attribute in HttptSession and ServletContext?

 
Ramesh Lakshmanan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
What is the Difference B/W Setting attribute in HttptSession and ServletContext?
Can i get one Real Time example for this.
thanks
Ramesh
 
Ramesh Lakshmanan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
Just had quick think about the scenario which i posted just now..
Setting an Attribute in ServletContext:
If an Attribute has been set using this Context , different client(I mean browser) accessing the Same Servlets can share that.
But the Session can not be shared like that , Session is visible only for that Client(I mean only for that Browser).
Am i going in an correct Light Path?
Please correct me if i am wrong?
thanks
Ramesh
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i agree with you about Session...
But about ServletContext, i dont agree with you...
Because if we set attributes in ServletContext, all servlet and jsp page within its web application can get that attributes. So not only from the same servlet.
Correct me if i am wrong...
daniel
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramesh Lakshmanan:
Setting an Attribute in ServletContext:
If an Attribute has been set using this Context , different client(I mean browser) accessing the Same Servlets can share that.

No.Its accessiblity is more broader ...
all the servlets and jsp's can access this !!!
For all servlets and jsp's it like a window to the environment,assuming application is not distributed in multiple JVM"s, and they all share one environment & hence its accessible to all.


But the Session can not be shared like that , Session is visible only for that Client

Right


(I mean only for that Browser).

Wrong.A user can
open multiple browser windows and send requests through multiple windows. In such
instances, all the requests belong to the same session and all the threads processing these
requests will be able to access the session attributes simultaneously.
HTH
-Varun
 
Ramesh Lakshmanan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fisher & varun Khanna ,
Just now i tried with some samples.What you guys are telling is correct.Thanks for your feedback(s)
Thanks,
Ramesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic