Hi,
apparently to achieve what you want you need to store in your bean class a
handle to any servlet class to get access to servlet context, from which you
can retrieve other beans.
However it is not a good idea in general as you introduce 2 way dependency
between your logic (beans) and presentation classes (servlets). You even
have a syclic dependency which is a no-go in OOP.
Bean->Servlet->ServletContext->Bean->etc.
Better approach would be to create a singleton class that would hold other
beans, whilc at the same time residing in the same business layer (or maybe
even the same package) as beans.
Vadim Shun
NEW Corp
Dulles, VA
>>
Date: Thu, 20 Jul 2000 17:03:55 GMT
From: Serbulent Ozturk <[EMAIL PROTECTED]>
Subject: Beans accessing ServletContext
Hello,
I have been trying to provide JavaBeans with an access to specific JavaBean
instance stored in various scopes, i.e. application (ServletContext),
session, request:
- I create an instance of a bean and store it in some scope, e.g.
application.
- I can retrieve that bean instance in another servlet or a jsp by matching
the scope, id and class.
But the problem is I can not access that bean access from other beans. Does
the bean have to extend javax.servlet.http.HttpServlet to use the
getServletContext() etc.?
I have tried to have all the methods and instance variables as static and
put an instance of that class in the ServletContex to prevent unwanted
garbage collection. It looked OK with JDK1.2 but it looks very unstable
with jdk1.3.
Does anyone have any suggestion?
Thanks
Bulent
________________________________________________________
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets