This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes 1) Request Attributes? 2) SessionListener? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "1) Request Attributes? 2) SessionListener?" Watch "1) Request Attributes? 2) SessionListener?" New topic
Author

1) Request Attributes? 2) SessionListener?

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi,

I have made a web-based application using JSP & servlets.

1) Query
Whenever my application is interacting the database for getting ResultsSet i am setting the request attribute as

request.setAttribute("ROWSFOUND","NO"); if no rows are found
else
request.setAttribute("ROWSFOUND","YES"); if rows are found

So what i would like know is that everytime a object would get created for attribute 'ROWSFOUND' or the same object values will be REPLACED for this attribute??

Because if everytime the object for attribute 'ROWSFOUND' would get created then it will take a lot of memory because i m not removing this request attribute.So if this is the thing what should i do?? And i dont want to remove this manually because if i would do that i will have to write a removeAttribute() statement in my each class which is interacting with the database & i have a lot of classes.


2) QueryI want to write a SessionListener class for this application which can automatically remove the session attribute's objects created after a particular time. So how to do this??


Thanks,
Jignesh
[ March 21, 2006: Message edited by: Bear Bibeault ]

Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
So what i would like know is that everytime a object would get created for attribute 'ROWSFOUND' or the same object values will be REPLACED for this attribute??



the same object values will be REPLACED
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830

So what i would like know is that everytime a object would get created for attribute 'ROWSFOUND' or the same object values will be REPLACED for this attribute??


You should think of a Map while thinking of Request. So just like Map can't have duplicate keys Request too.

So the old object will be replaced by the new one.
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Thanks for the reply,

So what about the memory occupied by the request attribute object.
You said it would get replaced so,if i am not mistaken, no extra memory would be wasted right??

Kindly sort out my second query also??

Thanks,
Jignesh
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes, the old string would be set free for garbage collection.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Wouldn't a Boolean true or false be a better choice than the strings "YES" and "NO"?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
but Bear, the attributes are set in the request. and boolean true and false wont be permitted as they are primitives.right??
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello Geetu,
Use Wrapper then.....if you are using JSE 5.0 then autoboxing will do the job

Shrinivas
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by geetu lalchandani:
but Bear, the attributes are set in the request. and boolean true and false wont be permitted as they are primitives.right??


I said Boolean, not boolean. I'd use the values Boolean.TRUE and Boolean.FALSE.
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
Boolean will still be a object right..
how does it make a difference to use Boolean or String(performance wise).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by geetu lalchandani:
Boolean will still be a object right..
how does it make a difference to use Boolean or String(performance wise).


Using Boolean will be more efficient because you won't have to do String comparisons... BUT that's a minor consideration. You should choose to use Boolean because it makes more sense than using strings with "YES" and "NO' or "TRUE" and "FALSE".
 
GeeCON Prague 2014
 
subject: 1) Request Attributes? 2) SessionListener?