This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JSP and the fly likes keep bean for only a few requests, not a whole session Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "keep bean for only a few requests, not a whole session" Watch "keep bean for only a few requests, not a whole session" New topic
Author

keep bean for only a few requests, not a whole session

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
What's the best way to create and use a bean for just one or two or three request and response cycles instead of keeping it in memory as long as the session is alive? I've never used a simple JavaBean whose life is set to the request--only ones that remain for the whole session. Is there a way to have it be a session bean, but then get rid of it when I determine I no longer need/want it around? Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

session.removeAttribute()


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Hemanth Pallavajula
Ranch Hand

Joined: Oct 07, 2004
Posts: 38
By using session.removeAttribute() we will be able to remove the particular attribute's data from the session.

By doing so, we will be having the data in the session even if we are not processing the request for which that part of the data is required. Basically, what i mean to say is that, even while processing those requests in which the data will not be used, we would be having the data in the session.

One solution that I want to provide is as follows:-
All the requests in which an attribute(e.g. countryCode) will be used, need to set in the web.xml (for Struts, struts-config.xml) a property which would indicate the web server that the attribute, "countryCode" needs to be set in the request scope whenever that particular request is being processed.

I hope I am clear. I would be glad to come out more clearly on my approach. And if what I said already exists, then it is purely coincidential ( I may not be having knowledge of it).


Cheers,<br />Hemanth...<br />(When opportunity doesn't knock, build a door.)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

I do not see how that addresses the issue. He's not talking about a static property that can be set in web.xml or anywhere else, but an active bean object whose scope needs to extend beyond the lifetime of a single request.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: keep bean for only a few requests, not a whole session
 
Similar Threads
add a bean to many servlets which share their data
Action method not getting called inside the dataTable
h:selectOneListBox validation trouble
Specific method for bean JSF!
how i can submit a form along with some parameters using javascript ?