dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Advanced
Mar 2, 2005

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Share Information with Other Web Resources Using ServletContext

The Servlet API provides the class javax.servlet.ServletContext, which has methods that work with data stored in context. Any servlet can store Java objects in that context and other servlets can use them. The objects are stored with a String key for uniqueness.

Here's how it works:

  1. Use setAttribute(String key, Object value) to store an attribute in context. key is the name of the attribute and value is the Java object to be stored.
  2. Use getAttribute(String key) to retreive the Java object corresponding to the value of key in context. If no object is found, null is returned.
  3. Remove attributes from context using remove(String key).
ServletContext can be used in other ways besides data sharing—for instance, working with RequestDispatcher or logging into the servlet log file.
Amit Tuli
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date