Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.removeAttribute()
 
Hemanth Pallavajula
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!