如何定期刷新jsp页面的特定部分

How to refresh specific part of jsp page periodically

本文关键字:定部 何定期 刷新 jsp      更新时间:2023-09-26

我有一个由表组成的jsp,表显示一些来自数据库的数据。现在我想每30秒刷新一次表。请帮助我解决这个问题。请找到下面的代码。

注意:我不想刷新整个页面。只有我想刷新jsp中的表。

empDetails.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
<center><h2>Employee Details</h2></center>
<form>
<center>
<div id="loadData">
<table border="2">
    <c:if test="${!empty empDetails}">
            <tr>
                <th>Employee ID</th>
                <th>Employee Name</th>
                <th>Salary</th>
                <th>Department</th>
            </tr>
            <c:forEach items="${empDetails}" var="emp">
                <tr>
                    <td><c:out value="${emp.empId}"/></td>
                    <td><c:out value="${emp.empName}"/></td>
                    <td><c:out value="${emp.salary}"/></td>
                    <td><c:out value="${emp.department}"/></td>
                </tr>
            </c:forEach>
    </c:if>
    </table>
    </div>
    </center>
</form>
</body>
</html>
function refreshFunction(){
  $.ajax({
     url: '/page.html',  //page or method that will return html
     success: function (data) {
         $('div#loadData').html(data);
     }
  });
}
setInterval(refreshFunction, /*interval*/)

看到美元。Ajax,它有很多有用的参数