The first time  you use the useBean tag, it creates a variable called
(whatever is in the id attribute) and checks in (whatever is in scope)
for an attribute named (whatever is in name). If it can't find one, it
instantiates an instance of (whatever is in class), and places it into
the (scope) attribute space, under the name (name). It also makes that
variable, the one named (id) reference this new object.

So now you have a variable (in your example) that is called myBigBean,
which you can use immediately in scriplets, etc.

The next time you want to use the variable, you have two options.

use a jsp:useBean tag again.  Because it checks the (scope), if you
already have an instance of (class) called (name) it will use the
existing object.  So useBean is used for both instantiation and storage,
and for retrieval.

The other option is to just use a scriptlet

<%  
n.m.c.BigBean myBigBean = (n.m.c.BigBean)
session.getAttribute("myBigBean");
%>

In fact, you could have done this entirely with scriptlets. The
following replaces the first usage of useBean:
<%
 n.m.c.BigBean myBigBean = (n.m.c.BigBean)
session.getAttribute("myBigBean"); 
 if (myBigBean == null) {
        myBigBean = new n.m.c.BigBean();
        session.setAttribute("myBigBean", myBigBean);
}
%>


but the point of using jsp:useBean is to avoid their usage (or at least
defer it). I would go with one or the other (use tags throughout, or use
code).


> -----Original Message-----
> From: Andoni [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, September 17, 2003 8:56 AM
> To: Tomcat Users List
> Subject: Session level beans.
> 
> 
> Hello,
> 
> I have a lot of JavaBeans that are initialised in my login 
> page using <java:useBean> tags. The scope of these beans is 
> set to session thus:
> 
> <jsp:useBean id="myBigBean" scope="session" 
> class="net.mysite.client.BigBean">
>     <% myBigBean.init(application, session); %>
> </jsp:useBean>
> 
> now if I use the variable myBigBean elsewhere in my site 
> should I be able to access this bean? Or is it necessary for 
> me to have a tag identifying this bean in *every* .jsp like this:
> 
> <jsp:useBean id="myBigBean" scope="session" 
> class="net.mysite.client.BigBean">
>     <% myBigBean.init(getServletContext(), session); %> </jsp:useBean>
> 
> The way I have it at the moment I have included these tags 
> but I have been told they are not necessary!  But when I 
> remove them and try to access myBigBean.doSomething() I just 
> get error messages saying myBigBean is unknown.
> 
> Thanks for any help or pointers to reference info.
> 
> Andoni.
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to