Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servletcontext-attribute

 
sri jaisi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we use servlet context to share common parameters between all the servlets in our application;we store them in web.xml(contextparam).we retrive them through getInitParameter;but servletcontext interface also has setAttribute;getattribute methods;where we have to use them and how
thaknz
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but servletcontext interface also has setAttribute;getattribute methods;where we have to use them and how

You can use those methods to share data (which might be the result of a calculation based on the user's answer on a form) between all the servlets in your application. However, the data isn't thread safe, so another request from another client can set those variables to something else before the servlets handling the first request have a chance to read them.
[ October 14, 2006: Message edited by: sven studde ]
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I believe, the parameters in the xml file are read only. The context parameters added and removed at runtime are read/write.

Be careful with the ServletContext. It is not necessarily workload managed across JVMs in a clustered environment, so not only is it not threadsafe, but contexts can also get out of sync. A centralized database is so much nicer to use in a workload managed environment.

Cheers!

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic