Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

List in Web-App  RSS feed

 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • 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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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 ]
 
Manoj Kumkumath
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
forgot the basics while working..

thnx
Neeraj.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!