In a code that follows Spring MVC, I have 2 lists in my java code that I would like to use in my JSP view. I set them like this:
public ModelAndView circularListView(HttpServletRequest request, Principal principal, HttpSession session, Locale locale, ModelAndView mav, int startOffset) {
//some code
mav.addObject("circularsList", circularsList);
mav.addObject("documentNameList", documentNameList);
return mav;
}
Now I would like to iterate on both lists circularsList
and documentNameList
in a single for loop in the JSP page, but it seems that I can only set one variable name like this:
<c:forEach items="${circularsList}" var="circular" varStatus="status">
To access a value in the second list which is documentNameList
, I do it like this:
<input type="hidden" id="circDocNam" value="${documentNameList[status.index]}"/>
Unfortunately, this does not seem to work, and the value in the above line is empty.
What to do?
In conclusion: How to access a list item using its index in JSP?