• 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

Servlet Context

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good
 
Syed Zackriya Hussainy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good
 
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic