2013-04-30 68 views
0

我有一个由表组成的jsp,表中显示的是来自数据库的一些数据。 现在我想每30秒刷新一次表格。请帮我解决这个问题。请找到下面的代码。如何定期刷新jsp页面的特定部分

注意:我不想刷新整个页面。只有我想刷新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> 
+1

那么,你有什么尝试?你正在寻找一个JavaScript解决方案或什么?由于JSP是一种服务器端技术,JSP与这个问题没有任何关系。如果您的服务器支持,您可以每30秒进行一次javascript轮询,或者使用websocket推送。 – eis 2013-04-30 07:36:55

+0

搜索这些:window.setInterval,AJAX,jQuery $ .get或$ .post – 2013-04-30 07:39:50

回答

0
function refreshFunction(){ 
    $.ajax({ 
    url: '/page.html', //page or method that will return html 
    success: function (data) { 
     $('div#loadData').html(data); 
    } 
    }); 
} 

setInterval(refreshFunction, /*interval*/) 

见$阿贾克斯,它有很多有用的参数。