You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Colic <al...@pop-ware.com> on 2001/04/09 20:51:31 UTC

Please explain these lines to me.

Hi,

I amusing the example struts app to modify my present web app. I am using
one bean across a number of forms. Each form populates this bean.

In my loginaction servlet I create an instance of a bean and place it into
the session.

I then intend to have that bean used across all forms. In the second page I
have the following lines in my Page2action servlet:

if(mapping.getAttribute()!=null)
    {
      if("request".equals(mapping.getScope()))
        {
          request.removeAttribute(mapping.getAttribute());
        }
      else
        {
          session.removeAttribute(mapping.getAttribute());
        }
    }
    return (mapping.findForward("success"));


Why are these lines there. I can understand that if the present bean being
used is of request scope then take it out but then why are you also taking
out a bean that is of session scope? When my app gets to page 3 the info
entered on page one is gone. What I think is happening is that page 2 fills
the bean, the page 2 action servlet removes the bean from the session. When
page 3 gets the bean, it does not exist so it is created but it is empty.

Should the remove bean from session lines be removed?

Thanks

Alex


Re: Please explain these lines to me.

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 9 Apr 2001, Alex Colic wrote:

> Hi,
> 
> I amusing the example struts app to modify my present web app. I am using
> one bean across a number of forms. Each form populates this bean.
> 
> In my loginaction servlet I create an instance of a bean and place it into
> the session.
> 
> I then intend to have that bean used across all forms. In the second page I
> have the following lines in my Page2action servlet:
> 
> if(mapping.getAttribute()!=null)
>     {
>       if("request".equals(mapping.getScope()))
>         {
>           request.removeAttribute(mapping.getAttribute());
>         }
>       else
>         {
>           session.removeAttribute(mapping.getAttribute());
>         }
>     }
>     return (mapping.findForward("success"));
> 
> 
> Why are these lines there. I can understand that if the present bean being
> used is of request scope then take it out but then why are you also taking
> out a bean that is of session scope? When my app gets to page 3 the info
> entered on page one is gone. What I think is happening is that page 2 fills
> the bean, the page 2 action servlet removes the bean from the session. When
> page 3 gets the bean, it does not exist so it is created but it is empty.
> 
> Should the remove bean from session lines be removed?
> 

In general, you want to remove attributes that are no longer required --
especially in the case of session attributes -- so that the memory space
those beans utilize can be garbage collected.  If you need to keep a bean
around for a while, by all means do not remove it (until you want to).

You should also note that the logic above removes the form bean itself,
not the User object that is stored in the session to denote a successful
logon.

> Thanks
> 
> Alex
> 
> 

Craig



RE: Please explain these lines to me.

Posted by Kurt Olsen <ko...@get2hawaii.com>.
Alex,
I'm guessing that the removal of the login bean from the session scope is
only something done for a login action in order to remove the users password
from the session. I can sorta see the sense in that. I copied/pasted the
login page myself when I started my first struts app and was wondering why I
was removing my beans. Since then I've removed those lines from my pages and
am using the struts.config to manage my formbeans scopes etc.


-----Original Message-----
From: Alex Colic [mailto:alex.colic@pop-ware.com]
Sent: Monday, April 09, 2001 8:52 AM
To: Struts
Subject: Please explain these lines to me.


Hi,

I amusing the example struts app to modify my present web app. I am using
one bean across a number of forms. Each form populates this bean.

In my loginaction servlet I create an instance of a bean and place it into
the session.

I then intend to have that bean used across all forms. In the second page I
have the following lines in my Page2action servlet:

if(mapping.getAttribute()!=null)
    {
      if("request".equals(mapping.getScope()))
        {
          request.removeAttribute(mapping.getAttribute());
        }
      else
        {
          session.removeAttribute(mapping.getAttribute());
        }
    }
    return (mapping.findForward("success"));


Why are these lines there. I can understand that if the present bean being
used is of request scope then take it out but then why are you also taking
out a bean that is of session scope? When my app gets to page 3 the info
entered on page one is gone. What I think is happening is that page 2 fills
the bean, the page 2 action servlet removes the bean from the session. When
page 3 gets the bean, it does not exist so it is created but it is empty.

Should the remove bean from session lines be removed?

Thanks

Alex