• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

1) Request Attributes? 2) SessionListener?

 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the old string would be set free for garbage collection.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't a Boolean true or false be a better choice than the strings "YES" and "NO"?
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic