java - Array result keep getting the last result -


i put partial of code think source of problem not figure out hence why @ stackoverflow now. anyways class set data , pass array.

public arraylist<select.rates> casegetrates() throws ratetableexception, sessiondisconnectedexception {      try {         for(int i=0;i < arrayrate.size();i++){              arraylist<select.rates> arr = new arraylist<select.rates>();              this.setpair(array[0]);              this.setbid((array[2]));              this.setask((array[3]));              arr.add(this);         }         return arr;       } finally{}  } 

when system.out.print data set in class gives me:

eur/usd 1.12372 1.12384  usd/jpy 100.622 100.641  

which correct , displayed on webpage.however when pass data servlet

try {     arraylist<select.rates> rates = example.casegetrates();      for(int i=0;i < rates.size();i++){         system.out.println("");         system.out.println(rates.get(i).getpair());         system.out.println(rates.get(i).getbid());         system.out.println(rates.get(i).getask());     }     request.setattribute("rates", rates); }  request.getrequestdispatcher("/newfile.jsp").forward(request, response); 

the result on servlet is:

usd/jpy 100.622 100.641  usd/jpy 100.622 100.641 

the result loop twice data seems overwritten , still can't figure out why happening. hope can pin point mistake.

create arraylist object outside loop

and inside loop create new object adding arraylist

try {     arraylist<select.rates> rates = example.casegetrates();      for(int i=0;i < rates.size();i++){         // create new object here , add arraylist     }     request.setattribute("rates", rates); }    request.getrequestdispatcher("/newfile.jsp").forward(request, response); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -