This is one of the cool things about JSP 1.0. Beans are stored in their
corresponding scope variable.
So, application scope beans are stored in the 'application' implicit
variable. You can then pass the application object (or the pageContext) to
the bean.
<jsp:useBean id='DBConnection' class='com.caucho.sql.DBConnection'
scope='application'/>
<jsp:useBean id='test' class='com.caucho.test.Test'/>
<%
test.doSomethingCool(application);
%>
Where 'doSomethingCool' uses application.getAttribute("DBConnection") to get
the database connection.
Or if your JSP engine supports request time attribute values, you could
initialize test by:
<jsp:useBean id='test' class='com.caucho.test.Test'>
<jsp:setProperty name='test' property='pageContext' value='<%= pageContext
%>'/>
</jsp:useBean>
Then you could pull out the connection using:
pageContext.getServletContext().getAttribute("DBConnection");
Scott Ferguson
Caucho Technology
Drew Cox wrote:
> I hope l'm missing something simple, but how do you get a reference to a
> JSP bean defined with USEBEAN from within another JSP bean ?
>
> Specifically, l would like to do some simple DB connection pooling by
> creating an "application" scope bean "DBConnection", that loads the JDBC
> driver & creates a connection object which it stores in an instance
> variable.
>
> This would do some checking to ensure it was only created once.
>
> The idea is that other beans used on the JSP page could access the
> connection stored in the "DBConnection" bean to create their query
> statements.
>
> But, l can't find a method by which l can get access to other beans
> defined at any JSP scope level from wlthin the bean code.
>
> Thanks
> Drew
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JSP-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".