[英]How can I update the highscore of a game with a database without reloading the page?
[英]How can I update variables on jsp page without reloading page?
我有一個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>
不幸的是,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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.