如何在不重新加载页面的情况下更新jsp页面上的变量?

时间:2019-05-20 10:50:02

标签: javascript java html spring jsp

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

这是我的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>

1 个答案:

答案 0 :(得分:0)

不幸的是,使用模型数据填充了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