简体   繁体   中英

I want to display one by one value in JSP from spring controller

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

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:

  1. declare a list outside the loop
  2. now, inside the loop, add values into the list
  3. outside the loop, return the jstl page

This should work. Let me know if you face any difficulties doing this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM