【问题标题】:How can I update variables on jsp page without reloading page?如何在不重新加载页面的情况下更新 jsp 页面上的变量?
【发布时间】:2019-05-20 10:50:02
【问题描述】:

我有一个 jsp 页面,其中有几个变量,所有变量在每一秒内都会有不同的值,因为后端的一些代码会改变它们。当用户加载以下页面时,将看到这些数字为零,但随着时间的推移,这些值应该更新并显示在此页面上,所以基本上它应该看起来像一个计时器。

这是我的jsp页面:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Process</title>
</head>
<body style="background-color:aquamarine;">
<h2>${info}</h2>
<h2>Number of Xs:</h2>
<h2>${numberOfX}</h2>
<h2>Completed Xs:</h2>
<h2>${completedInfo}</h2>
<h2>Elapsed time:</h2>
<h2>${elapsedTime}</h2>
<form action="/" method="get">
    <table>
    <tr>    
    <td><input type="submit" name="button1" value="BACK" /></td>                                            
    </tr>
    </table>
</form> 
</body>
</html>

【问题讨论】:

    标签: javascript java html spring jsp


    【解决方案1】:

    不幸的是,jsps 被模型数据填充了一次。

    您可以使用服务器端事件: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events https://www.baeldung.com/spring-mvc-sse-streams

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 2019-07-25
      • 2020-04-20
      • 1970-01-01
      • 2021-07-17
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 2014-04-12
      相关资源
      最近更新 更多