7

So, I have a list that I passed it through the model from my Spring controller to JSP. How do I iterate through the list inside the JSP?

Assume, the list has several hyperlinks that I would like to display in JSP. How to do this without scriptlets?

3
  • 1
    Depends how you're returning it, if it's returning an array of JSON objects or if it's directly use a for loop in the JSP. Commented Oct 3, 2013 at 13:42
  • I should iterate in JSP itself! Commented Oct 3, 2013 at 13:54
  • 1
    Yeah but you could write say a jQuery loop in a jsp file, you mention you're using a Spring controller so you may be just using it to query JSON. @Chirag Kathiriya has the right answer if it's just directly through the JSP. Commented Oct 3, 2013 at 14:08

1 Answer 1

12

you can use jstl tag and display the list

<c:forEach var="listVar" items="${listName}"> //add the model attribute of list in items
    <option value ="10"><c:out value="${listVar.attribute}"/></option>
</c:forEach>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.