• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting attributes in the scopes

 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we set primitive's(say int Array) into the Attributes??

ex:
<%
int[] ia = { 10, 110, 1110 };
request.setAttribute("ia", ia);
%>
 
Pavan Sambare
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you can. Because an int[] is also an object and not a primitive.
 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I replace it to only int/float?
 
Pavan Sambare
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will not be able to set only int/float as the setAttribute method's signature is request.setAttribute(String, Object). You would need to set them as Wrappers.
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so because we can set primitive on setAttribute method.
I did myself without any headache.

best regards,
omi
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so because we can set primitive on setAttribute method.[/QB]
That's because your JRE runtime is version 5 or later - so it's using auto-boxing to automatically wrap the primitive into its associated wrapper, and un-box it again as required... it's still storing an object!
 
S Sravs
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Array is an object.
so we can setAttribute of request,session,context.For the code session scope doesn't make any sense but since array is object you can set Attribute for any scope.

Sravanthi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic