Home > OS >  Using ArrayList in a sub-template on .jsp page
Using ArrayList in a sub-template on .jsp page

Time:02-16

I have a JSP home page with a menu. I want that menu to be on multiple pages so I created a menu.jsp template. I imported, all static source code appears but the <c:forEach /> tag is not picking it up. When I print (just put it plainly in the html) out my ${allCategories} variable I get all the data correctly.

In a controller, I set model.addAttribute("allCategories", categoryService.getPrimaryCategories());

home.jsp where the categories were before is importing <jsp:include page="menu.jsp"/>

in menu.jsp I am unable to get <c:forEach items="${allCategories}" var="category"> to work but when I just put <p>${allCategories}</p> at the beginning of the file it shows stuff like [Category(id=1281, name=Bundles, image=https://images... How do I get the data correctly in the sub-template so it works like directly on the page?

CodePudding user response:

You could try using the JSP include directive. It is used to include a file during the translation phase. For example,

<%@ include file = "menu.jsp" >
  • Related