File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes erasing bean from scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "erasing bean from scope" Watch "erasing bean from scope" New topic

erasing bean from scope

Baba Bizlowsky
Ranch Hand

Joined: Dec 15, 2003
Posts: 39

Is there a quick way to invalidate a bean? I understand that <jsp:setProperty> tag leaves everything as it were if I send in the null-values. But what if I want to erase the data from the bean (e.g. when the user is signing out)? Is invalidating the session the only way?

Thanks in advance. Cheers!
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

There is HttpSession.removeAttribute.
You could also create your own clearProperties method which empties all of the properties in the bean.
If the bean implements HttpSessionBindingListener, you could have the method called automatically when the object is removed from session.

You could also wrap the clearProperties method with a plain setter or getter and call it from your jsp with a jsp:setProperty or jsp:getProperty tag.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: erasing bean from scope
It's not a secret anymore!