• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Context

 
Vikas Aggarwal
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
 
Syed Zackriya Hussainy
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
 
L Goundalkar
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.
 
Anthony Villanueva
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().
 
sandy gupta
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?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic