• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

List in Web-App

 
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

following is the sample code that, I am trying..


*****
month is an list object containing months (Jan,Feb...Dec) , added in a helper class

*****


List list1=(List)request.getAttribute("months");

list1.add(0,"test");



List list2=(List)request.getAttribute("months");

list2.get(0).toString() is giving value as "test".

How the request list attribute is getting changed.

Please help me to understand this.


Regards,
Neeraj.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a concept of 'getting by reference' and 'getting by value'?
[ January 04, 2006: Message edited by: Adeel Ansari ]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neeraj,
This issue doesn't have to do anything with JSP. It's just a reference problem. When you say
list1.add(0,"test");
At this point the object reference in list1 is same as the object reference of the List in request.

If you don't want the changes to list1 to get reflect in the list hold by request object, then create new list1 object passing values of list in request as shown below.
List list1=new ArrayList((List)request.getAttribute("months"));

Instead of ArrayList, use the appropriate concrete class you are using
-Manoj
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
forgot the basics while working..

thnx
Neeraj.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic