You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniel Chacón Sánchez <da...@gmail.com> on 2006/09/25 23:06:38 UTC

Erase Only some Session Objests and variables

Hi all,

How I can kill son objects and variables in session, without kill everything
in session like with session.invalidate().

I want that some objects always be in session and when I press a menu option
all other variables or object that are in session be erase.

i can´t use removeAttribute(..); because I don´t know the name of all
objects and variables that be in session in a moment. I need to erase
everything from sesion except son object that always need in session, how
can i do that?

I'm using struts framework

Re: Erase Only some Session Objests and variables

Posted by Daniel Chacón Sánchez <da...@gmail.com>.
thaaaaaaaaaaaaaanks!!!!!!!!!

I will use it

2006/9/25, Heidy Gutiérrez Guzmán <he...@gmail.com>:
>
> You can use this code:
>
>    Enumeration enumeration = session.getAttributeNames();
>    while (enumeration.hasMoreElements()) {
>     String element = (String) enumeration.nextElement();
>        session.removeAttribute(element);
>    }
>
> If yo don't have delete any element, you can do this:
>
>    Enumeration enumeration = session.getAttributeNames();
>    while (enumeration.hasMoreElements()) {
>     String element = (String) enumeration.nextElement();
>     if(!element.matches("notDeleteElement") )
>         session.removeAttribute(element);
>    }
>
>

Re: Erase Only some Session Objests and variables

Posted by Heidy Gutiérrez Guzmán <he...@gmail.com>.
You can use this code:

   Enumeration enumeration = session.getAttributeNames();
   while (enumeration.hasMoreElements()) {
    String element = (String) enumeration.nextElement();
       session.removeAttribute(element);
   }

If yo don't have delete any element, you can do this:

   Enumeration enumeration = session.getAttributeNames();
   while (enumeration.hasMoreElements()) {
    String element = (String) enumeration.nextElement();
    if(!element.matches("notDeleteElement") )
        session.removeAttribute(element);
   }

Re: Erase Only some Session Objests and variables

Posted by Daniel Chacón Sánchez <da...@gmail.com>.
Yeap :-) I think the better is a properties file

2006/9/25, paz.periasamy@axa.com.au <pa...@axa.com.au>:
>
> Hello Daniel,
>
> The preserve list could be upto your implementation. It could be a
> Delimited String which you read from a property file and you can store it
> in a ArrayList.
>
> Loop the arrayList, get the entires, and compare it with the Session
> Attributes
>
> session.getAttributeName ().
>
> If they match, dont remove. If they dont match, remove. This should be a
> simple logic.
>
> Thanks and regards,
> Pazhanikanthan. P (Paz)
>
> Consultant for AXA,
> Senior Software Engineer,
> HCL Australia Services Pty. Ltd.
> Off   : +61-3-9618-4085
> Mob : +61-0411-354-838
>
>
>
>
> "Daniel Chacón Sánchez" <da...@gmail.com>
> 26/09/2006 08:41 AM
> Please respond to "Struts Users Mailing List"
>
>         To:     "Struts Users Mailing List" <us...@struts.apache.org>,
> jhking@airmail.net
>         cc:
>         Subject:        Re: Erase Only some Session Objests and variables
>
>
> What do you suggest me to use for keep that "preserve" names? A file, an
> arrayList, or what? An example code of the use of that with the code that
> Heidy gived??
>
>
> 2006/9/25, Jason King <jh...@airmail.net>:
> >
> > Daniel Chacón Sánchez wrote:
> > > son = some :P
> > >
> > > 2006/9/25, Daniel Chacón Sánchez <da...@gmail.com>:
> > >>
> > >> Hi all,
> > >>
> > >> How I can kill son objects and variables in session, without kill
> > >> everything in session like with session.invalidate().
> > >>
> > >> I want that some objects always be in session and when I press a menu
> > >> option all other variables or object that are in session be erase.
> > >>
> > >> i can´t use removeAttribute(..); because I don´t know the name of all
> > >> objects and variables that be in session in a moment. I need to erase
> > >> everything from sesion except son object that always need in session,
> > >> how
> > >> can i do that?
> > >>
> > >> I'm using struts framework
> > >>
> > >
> > Since the session object is a map you could get a list of keys and for
> > each key compare it to your list of "preserve" names.  If its not in the
> > name, remove it.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> _____________________________________________________________________
> This e-mail has been scanned for viruses by MCI's Internet Managed
> Scanning Services - powered by MessageLabs. For further information
> visit http://www.mci.com
>
>
> *********************************************************************************
> Important Note
> This email (including any attachments) contains information which is
> confidential and may be subject to legal privilege.  If you are not
> the intended recipient you must not use, distribute or copy this
> email.  If you have received this email in error please notify the
> sender immediately and delete this email. Any views expressed in this
> email are not necessarily the views of AXA.   Thank you.
>
> **********************************************************************************
>
>

Re: Erase Only some Session Objests and variables

Posted by pa...@axa.com.au.
Hello Daniel,

The preserve list could be upto your implementation. It could be a 
Delimited String which you read from a property file and you can store it 
in a ArrayList.

Loop the arrayList, get the entires, and compare it with the Session 
Attributes

session.getAttributeName ().

If they match, dont remove. If they dont match, remove. This should be a 
simple logic.

Thanks and regards,
Pazhanikanthan. P (Paz)

Consultant for AXA,
Senior Software Engineer,
HCL Australia Services Pty. Ltd.
Off   : +61-3-9618-4085
Mob : +61-0411-354-838




"Daniel Chacón Sánchez" <da...@gmail.com>
26/09/2006 08:41 AM
Please respond to "Struts Users Mailing List"
 
        To:     "Struts Users Mailing List" <us...@struts.apache.org>, 
jhking@airmail.net
        cc: 
        Subject:        Re: Erase Only some Session Objests and variables


What do you suggest me to use for keep that "preserve" names? A file, an
arrayList, or what? An example code of the use of that with the code that
Heidy gived??


2006/9/25, Jason King <jh...@airmail.net>:
>
> Daniel Chacón Sánchez wrote:
> > son = some :P
> >
> > 2006/9/25, Daniel Chacón Sánchez <da...@gmail.com>:
> >>
> >> Hi all,
> >>
> >> How I can kill son objects and variables in session, without kill
> >> everything in session like with session.invalidate().
> >>
> >> I want that some objects always be in session and when I press a menu
> >> option all other variables or object that are in session be erase.
> >>
> >> i can´t use removeAttribute(..); because I don´t know the name of all
> >> objects and variables that be in session in a moment. I need to erase
> >> everything from sesion except son object that always need in session,
> >> how
> >> can i do that?
> >>
> >> I'm using struts framework
> >>
> >
> Since the session object is a map you could get a list of keys and for
> each key compare it to your list of "preserve" names.  If its not in the
> name, remove it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

_____________________________________________________________________ 
This e-mail has been scanned for viruses by MCI's Internet Managed 
Scanning Services - powered by MessageLabs. For further information 
visit http://www.mci.com

*********************************************************************************
Important Note
This email (including any attachments) contains information which is 
confidential and may be subject to legal privilege.  If you are not 
the intended recipient you must not use, distribute or copy this 
email.  If you have received this email in error please notify the 
sender immediately and delete this email. Any views expressed in this 
email are not necessarily the views of AXA.   Thank you.
**********************************************************************************

Re: Erase Only some Session Objests and variables

Posted by Daniel Chacón Sánchez <da...@gmail.com>.
What do you suggest me to use for keep that "preserve" names? A file, an
arrayList, or what? An example code of the use of that with the code that
Heidy gived??


2006/9/25, Jason King <jh...@airmail.net>:
>
> Daniel Chacón Sánchez wrote:
> > son = some :P
> >
> > 2006/9/25, Daniel Chacón Sánchez <da...@gmail.com>:
> >>
> >> Hi all,
> >>
> >> How I can kill son objects and variables in session, without kill
> >> everything in session like with session.invalidate().
> >>
> >> I want that some objects always be in session and when I press a menu
> >> option all other variables or object that are in session be erase.
> >>
> >> i can´t use removeAttribute(..); because I don´t know the name of all
> >> objects and variables that be in session in a moment. I need to erase
> >> everything from sesion except son object that always need in session,
> >> how
> >> can i do that?
> >>
> >> I'm using struts framework
> >>
> >
> Since the session object is a map you could get a list of keys and for
> each key compare it to your list of "preserve" names.  If its not in the
> name, remove it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Erase Only some Session Objests and variables

Posted by Jason King <jh...@airmail.net>.
Daniel Chacón Sánchez wrote:
> son = some :P
>
> 2006/9/25, Daniel Chacón Sánchez <da...@gmail.com>:
>>
>> Hi all,
>>
>> How I can kill son objects and variables in session, without kill
>> everything in session like with session.invalidate().
>>
>> I want that some objects always be in session and when I press a menu
>> option all other variables or object that are in session be erase.
>>
>> i can´t use removeAttribute(..); because I don´t know the name of all
>> objects and variables that be in session in a moment. I need to erase
>> everything from sesion except son object that always need in session, 
>> how
>> can i do that?
>>
>> I'm using struts framework
>>
>
Since the session object is a map you could get a list of keys and for 
each key compare it to your list of "preserve" names.  If its not in the 
name, remove it.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Erase Only some Session Objests and variables

Posted by Daniel Chacón Sánchez <da...@gmail.com>.
son = some :P

2006/9/25, Daniel Chacón Sánchez <da...@gmail.com>:
>
> Hi all,
>
> How I can kill son objects and variables in session, without kill
> everything in session like with session.invalidate().
>
> I want that some objects always be in session and when I press a menu
> option all other variables or object that are in session be erase.
>
> i can´t use removeAttribute(..); because I don´t know the name of all
> objects and variables that be in session in a moment. I need to erase
> everything from sesion except son object that always need in session, how
> can i do that?
>
> I'm using struts framework
>