File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Decalring a int variable and using it in for loop in JSTL or EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Decalring a int variable and using it in for loop in JSTL or EL" Watch "Decalring a int variable and using it in for loop in JSTL or EL" New topic
Author

Decalring a int variable and using it in for loop in JSTL or EL

Murali Charan
Greenhorn

Joined: May 04, 2007
Posts: 11
Hi,

I would like to declare a int variable and use it as the looping variable.

Just like this

for(int i=0; i<10; i++)
{
// do something
}

I want to do this in a JSP.

I can do it in scriplet. But I dont want to use a scriplet and want the do it using either a JSTL (<c:forEach>) or EL.

I am able to iterate through a List using <c:forEach> will I able able to do this using <c:forEach> or anyother JSTL tags.

Please let me know.

Thanks,
Murali
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
<c:forEach> Tag should definitely have an items attribute. So, this can not be used exactly as normal for loop.

This can be used effectively in a situation like "If you want to display list of people or list of strings in a jsp......you can iterate it using this tag."
[ May 28, 2008: Message edited by: Prasad Tamirisa ]

Regards,
Durga Prasad
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

It is possible.

Ex:



- Marimuthu Madasamy
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Originally posted by Marimuthu Madasamy:
It is possible.

Ex:



I never know this....Thanks Madasamy.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There is also a varStatus attribute which has index and count properties.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Decalring a int variable and using it in for loop in JSTL or EL