简体   繁体   English

我想从 spring controller 在 JSP 中一一显示值

[英]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 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.引用您的评论: 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循环外,返回jstl页面

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:要在 JSP 页面中使用 JSTL 核心标签,请添加以下 taglib 指令:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

And to iterate list values, JSTL core have <c:forEach/> tag.为了迭代列表值,JSTL 核心有 <c:forEach/> 标签。 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参考: https://www.websparrow.org/spring/how-to-iterate-list-on-jsp-in-spring-mvc

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想知道在 spring 启动 web 应用程序中,当我们从一个 jsp 重定向到另一个 ZEC407C06B649DAA976E2 时 - i want to know in spring boot web app when we redirect from one jsp to another jsp 如何在Spring中将值从控制器传递到JSP页面? - How do I pass a value from a controller to a JSP page in Spring? 我需要将用户名的值从 Spring controller 传递到 JSP 页面 - I need to pass the value of userName from Spring controller to JSP page 从一个jsp获得价值到另一个jsp - Getting value from one jsp to another jsp 通过Spring Controller从JSP获取价值 - Get value from jsp via spring controller Spring-MVC:JSP<form action> 视图向控制器发送一系列值而不是单击按钮的一个值 - Spring-MVC: JSP <form action> view sends series of values to the controller instead of one value of the button clicked 我想使用Spring Controller中的Iterable在JSP文件中创建和填充列表项 - I want to create and populate list items in a JSP file using an Iterable from a Spring Controller 如何在Spring MVC Controller类中包含(加载)多个JSP文件? - How can I include(load) more than one jsp files in spring mvc controller class? 是否可以从JSP向Spring Controller发送多种类型的对象? - It is possible to send more than one type of object from JSP to Spring Controller? 在JSP之间传输数据。 从控制器(SPring MVC)以一种JSP接收数据。 - Transfer data between JSPs. Data is received in one of the JSP's from the controller (SPring MVC)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM