In my spring controller I have while loop which get new values everytime,I want to send new values to JSP from model attribute ,this is used for line chart
CodePudding user response:
Quoting your comment: I have while loop which extract text from many images ,this while loop in inside separate thread , I'm only getting the last value after while loop finishes ,model.attribute("send",newvalues) is inside while loop .
That means your values are immediately being replaced by the new ones inside the loop as they hold the same variable name.
So, either you need to store them in different variable or follow the below steps:
- declare a list outside the loop
- now, inside the loop, add values into the list
- outside the loop, return the jstl page
This should work. Let me know if you face any difficulties doing this.
CodePudding user response:
I hope this will help you for achieve your goals.
To use the JSTL core tags in JSP pages by adding the following taglib directive:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
And to iterate list values, JSTL core have <c:forEach/> tag. It will display the list values one by one.
<c:forEach var="emp" items="${empList}">
...
</c:forEach>
Dependency Required
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
reference: https://www.websparrow.org/spring/how-to-iterate-list-on-jsp-in-spring-mvc