You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@jakarta.apache.org by Arshak Navruzyan <ar...@netcomputing.com> on 1999/12/20 01:58:47 UTC

more useBean questions

Hello,

Since we are on the topic, let me ask this question.  How do you explicitly
delete a reference to a bean if the scope of the bean was been set to
"session" or for that matter "application."  I tried something simple like
setting the id variable to null but it doesn't seem to work.

<jsp:useBean id="rrs" scope="session"
class="com.netcomputing.emergency.Resource
Request" />
<%
rrs = null;
%>



Thank you,

Arshak



does bean get notified when it goes out of scope?

Posted by Ari Halberstadt <ar...@shore.net>.
Does a bean created via useBean get notified when it goes out of scope? It
would be nice to have a destroy() method called on the bean (or something
like that), so that the bean could release any resources like database
connections. I couldn't see any mention of this in the 1.1pr2 spec. Right
now, I don't know when a bean will go away (other than maybe being
finalized), so my jsp pages look like

BeanWannabe wannabe = new BeanWannabe();
try {
...
} finally {
  wannabe.destroy();
}

which is pretty ugly. I'd like to try replacing this with a useBean
directive with scope set to page or request and let the container take care
of destroying the bean.

-- Ari Halberstadt mailto:ari@shore.net <http://www.magiccookie.com/>



Re: more useBean questions

Posted by "Craig R. McClanahan" <cm...@mytownnet.com>.
Arshak Navruzyan wrote:

> Hello,
>
> Since we are on the topic, let me ask this question.  How do you explicitly
> delete a reference to a bean if the scope of the bean was been set to
> "session" or for that matter "application."  I tried something simple like
> setting the id variable to null but it doesn't seem to work.
>
> <jsp:useBean id="rrs" scope="session"
> class="com.netcomputing.emergency.Resource
> Request" />
> <%
> rrs = null;
> %>
>

This statement only erases your local reference to the bean (the rrs
variable).  It does not remove the bean from the surrounding scope.

To remove a session bean, do this (using servlet 2.2 syntax):

<%
    session.removeAttribute("rrs");
%>

If you are running under servlet API 2.0 or 2.1, this would be
session.removeValue() insteadl.

>
> Thank you,
>
> Arshak
>

Craig McClanahan