application.setAttribute("a","a");
how do I retrieve this "a" from the servlet?
thanks
Discussions
Web tier: servlets, JSP, Web frameworks: how to access object in application scope from servlet?
-
how to access object in application scope from servlet? (4 messages)
- Posted by: san kit cheng
- Posted on: March 15 2002 07:44 EST
Threaded Messages (4)
- how to access object in application scope from servlet? by Can Celik on March 15 2002 11:43 EST
- how to access object in application scope from servlet? by joseph yi on March 15 2002 14:00 EST
- how to access object in application scope from servlet? by san kit cheng on March 15 2002 22:55 EST
- how to access object in application scope from servlet? by joseph yi on March 20 2002 12:57 EST
- how to access object in application scope from servlet? by san kit cheng on March 15 2002 22:55 EST
-
how to access object in application scope from servlet?[ Go to top ]
- Posted by: Can Celik
- Posted on: March 15 2002 11:43 EST
- in response to san kit cheng
you need to use the ServletContext's getAttribute function -
how to access object in application scope from servlet?[ Go to top ]
- Posted by: joseph yi
- Posted on: March 15 2002 14:00 EST
- in response to san kit cheng
you must use a cast to the object depending on what you passed.
application.setAttribute("a","a");
so the first "a" is your key, the second "a" is a String object.
therefore,
String s = (String)application.getAttribute("a");
-
how to access object in application scope from servlet?[ Go to top ]
- Posted by: san kit cheng
- Posted on: March 15 2002 22:55 EST
- in response to joseph yi
this can only be work on jsp not in servlet -
how to access object in application scope from servlet?[ Go to top ]
- Posted by: joseph yi
- Posted on: March 20 2002 12:57 EST
- in response to san kit cheng
the servlet solution is the aforementioned ServletContext...
here's some snippets:
Servlet A
---------------------------------------
Vector v = new Vector();
ServletContext sc = getServletConfig().getServletContext();
sc.setAttribute("abc", v);
---------------------------------------
Servlet B
---------------------------------------
ServletContext sc = getServletConfig().getServletContext();
Vector v = (Vector)sc.getAttribute("abc");
---------------------------------------
JSP's application variable is just the ServletContext object