How Can I properly use an Application Context Object?

Hello there once again fellow developers!

Can anybody please tell me how to set a variable, (like a String or a Collection) inside Application Context?

To be more specific I need thecode on how to declare aServletContext Object and put a Collection named "users" into it.

and then perhaps How to retrieve such Collection...

Could anybody please put some sample code on how this is done?

I'd trully appreciate it.....

Thanks in advance

Jose

[505 byte] By [BCE_Josea] at [2007-11-26 22:59:53]
# 1

Inside a servlet class:ServletContext sc = this.getServletConfig().getServletContext();

sc.setAttribute("users", new ArrayList());

// ...

ArrayList users = (ArrayList)sc.getAttribute("users");

DrClapa at 2007-7-10 12:26:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Excelent Sir. Thank you very much....sincerely
BCE_Josea at 2007-7-10 12:26:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
but my suggestion i sput code of servlet context in "Synchronized "blockotherwise data may overlap
JspServleta at 2007-7-10 12:26:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Actually, call me ignorant but....I wouldn't where is such Block located.I need some more schooling.Thanks 4 the suggestion though
BCE_Josea at 2007-7-10 12:26:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

synchronized (this) {

// This is a synchronized block. The "this" can be any object, it's just the object

// where you want to depend the synchronization on.

}

Also see Java Tutorials covering Threading.

BalusCa at 2007-7-10 12:26:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...