I have this code in JSP:

У меня <c:forEach items="${storageListStorage+shopId}" var="storage"> <tr> <td><c:out value="${storage.productDto.categoryDto.nameCategory}"> </c:out></td> <td><c:out value="${storage.productDto.brand}"> </c:out></td> <td><c:out value="${storage.productDto.nameProduct}"> </c:out></td> <td><c:out value="${storage.amount}"> </c:out></td> <td><c:out value="${storage.shopDto.id}"> </c:out></td> </tr> </c:forEach> 

How to get the value of two variables from the session to items? In storageListStorage, I have a list and, depending on the shopId, the corresponding list should be displayed. With this syntax: items="${storageListStorage+shopId}" , I items="${storageListStorage+shopId}" error. If I write just items="${storageListStorage1} , then everything works. Who can suggest a solution?

  • Why don't you make a Map<Integer, Storage> , call it for example storageMap and use Items="${storageMap[shopId]}" ? And so they didn’t guess in EL to calculate variable names. This is not an easy thing. - Sergey
  • You can also try the function public Storage storageFunc(Integer shopId) { if (shopId == 1) return storageListStorage1; ... } public Storage storageFunc(Integer shopId) { if (shopId == 1) return storageListStorage1; ... } , items="${storageFunc(shopId)}" . - Sergey
  • @Sergey is not recommended to use JAVA code in JSP, but I will try this option, thanks) ps what is EL? ) - Ponomarenko Oleh
  • Actually, I did not think about java in JSP. How do your storageListStorage and shopId get into JSP? Similarly, the map and function, i.e. properties and methods of what is called a model. - Sergey

0