Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

print value outside while loop

 
somu sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to print values in html table outside while loop. I can not do it in while loop since my header gets repeated for each iteration.
I want something like...
NAME COUNTRY PHONENO
abc USA 0000000
pqr AUS 1111111

I have my code like ,
Iterator myItr = list.iterator();
while(myItr.hasNext()){
Object[] obj= (Object[]) myItr.next();
String myName = (String) obj[0];
String myCountry =(String)obj[1];
String myPhone =(String)obj[2];
data = "<html><body><TABLE><tr><td><b>NAME</td><td><b>COUNTRY</td><td><b>PHONENO</td></tr><tr><td>"+myName+"</td><td>"+myCountry+"</td><td>"+myPhone"+</td></tr></TABLE></body></html>";
out.print(data);
}

Here header part is also repeated again n again.
the output is coming as ,
NAME COUNTRY PHONENO
abc USA 0000000
NAME COUNTRY PHONENO
pqr AUS 1111111
NAME COUNTRY PHONENO
xyz AUS 2222222
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi You can achieve the desired result from the following code.

 
somu sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Mangal wrote:Hi You can achieve the desired result from the following code.


Thanks it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic