| Author |
Display the array length using JSTL
|
Romeo Ranjan
Ranch Hand
Joined: Feb 23, 2009
Posts: 90
|
|
Hi all,
I am looping through an array and here is my code
The problem is the output i get
Count 1
Count 2
Count 3
It loops through the array and prints each time. What I want is I want to assign
the count to a variable and display the count like this.
Count 3
How do I go about doing this?
|
SCJP 6.0
|
 |
D. Ogranos
Ranch Hand
Joined: Feb 02, 2009
Posts: 213
|
|
I don't really get what you want to achieve here? The count value IS already in a variable you can print out (status.count), and it comes out in the form you want. Or do you only want to print it if count has a specific value (like 3 here)? You can check that using
|
 |
Romeo Ranjan
Ranch Hand
Joined: Feb 23, 2009
Posts: 90
|
|
D. Ogranos wrote:I don't really get what you want to achieve here? The count value IS already in a variable you can print out (status.count), and it comes out in the form you want. Or do you only want to print it if count has a specific value (like 3 here)? You can check that using
Thank you very much for the reply. Sorry for not being clear. I want only the final count value alone. Everytime it loops through it prints Count 1 Count 2 and so on.
But what I want is the total count alone, only the value 3. How can I achieve this? Hope I am clear
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
Instead of outputting the count value, just assign it to a variable. Then output that variable after the loop is finished.
|
 |
Romeo Ranjan
Ranch Hand
Joined: Feb 23, 2009
Posts: 90
|
|
Paul Clapham wrote:Instead of outputting the count value, just assign it to a variable. Then output that variable after the loop is finished.
Hi Paul
Would be possible for you to show an example so that I could learn?
Thanks
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Which one are you having trouble with? Assigning something to a variable, or displaying the value of a variable?
Edit: No, never mind. I see you already know how to display the value of a variable. So it must be assigning something to a variable which is your question. You would use theelement for that.
|
 |
Romeo Ranjan
Ranch Hand
Joined: Feb 23, 2009
Posts: 90
|
|
Paul Clapham wrote:Which one are you having trouble with? Assigning something to a variable, or displaying the value of a variable?
Edit: No, never mind. I see you already know how to display the value of a variable. So it must be assigning something to a variable which is your question. You would use theelement for that.
Is it something like this?
|
 |
Romeo Ranjan
Ranch Hand
Joined: Feb 23, 2009
Posts: 90
|
|
|
I found out. Thanks a lot for helping me learn.
|
 |
 |
|
|
subject: Display the array length using JSTL
|
|
|