Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Servlet Context  RSS feed

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to know the following:
1. Is a Servlet Context is something private to the servlet who has created it?
2. Is it possible to access an attribute from servlet context in a servlet which has been previuosly set by another servlet.
3. What's the life cycle for the Servlet Context attribute?
Thanks
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good
 
Syed Zackriya Hussainy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good
 
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Is a Servlet Context is something private to the servlet who has created it?
Its not private. But the context provides the space for exchaging the data between web components.
Its is the View of servet towards the application.
2. Is it possible to access an attribute from servlet context in a servlet which has been
previuosly set by another servlet.
Yes it is possible to change the attribute of another servlet using the servlet context object of the first one.
3. What's the life cycle for the Servlet Context attribute?
I think it is same as Servlet.
Cheers.
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1. Is a Servlet Context is something private to the servlet who has created it?


There is only one ServletContext object per web application. All servlets and JSPs of that web application have access to the ServletContext object.


2. Is it possible to access an attribute from servlet context in a servlet which has been
previuosly set by another servlet.


Yes. You can consider the ServletContext object as a repository of "global" data for your web applications. However, the set/getAttribute() methods are not synchronized, so be careful.


3. What's the life cycle for the Servlet Context attribute?


Unlike a servlet, which can have many instances, a ServletContext attribute remains bound to the ServletContext object as long as the ServletContext object itself exsts, unless it is explicitly unbound by removeAttribute().
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are only 2 ways to remove attributes set in the servletContext:
1) as suggested above
2) by booting the server
The servlet context object is the "handle to a servlet" and exists for the life time of the application with which the servlet is bound
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The servlet context object is the "handle to a servlet" and exists for the life time of the application with which the servlet is bound


You mean "handle to the web application", right?
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!