wood burning stoves 2.0
The moose likes Servlets and the fly likes Removing session attributes with regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Removing session attributes with regex" Watch "Removing session attributes with regex" New topic
Author

Removing session attributes with regex

Kumara Sharma
Greenhorn

Joined: Sep 29, 2010
Posts: 6
Hi All,

I need to remove all the session attributes based on a pattern match.
Ex: Attribute keys being: book_firefox, book_chrome, etc.

Is there a way to remove all the attributes that start with book_* in a single statement.
HttpSession.removeAttribute(String) takes a single string as parameter, so how to achieve this?
Harsha Ka
Ranch Hand

Joined: Mar 14, 2010
Posts: 45

One possible way is using getAttributeNames() to get all the objects and iterate over these and check the key, and if the object key is matching your regex validation, remove this object.


SCJP 1.6,Preparing (Tryin to prepare) for scwcd
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Removing session attributes with regex
 
jQuery in Action, 3rd edition