我在春天和一般webdev新手。我正在春季開機寫小應用程序,在那裏我顯示真正的weatherstatus。數據在JpaRepository和HSQLDB的幫助下存儲。我可以使用Spring Boot和JSP強制更新內容/頁面嗎?
每分鐘我都會收集數據,解析並將其添加到存儲庫。邏輯完成了。
如何強制客戶端的瀏覽器刷新,當我得到新的實際數據?
我在春天和一般webdev新手。我正在春季開機寫小應用程序,在那裏我顯示真正的weatherstatus。數據在JpaRepository和HSQLDB的幫助下存儲。我可以使用Spring Boot和JSP強制更新內容/頁面嗎?
每分鐘我都會收集數據,解析並將其添加到存儲庫。邏輯完成了。
如何強制客戶端的瀏覽器刷新,當我得到新的實際數據?
隨着HTML:
要添加這種功能,而無需使用任何Ajax特性,可以使用以下元:
<meta http-equiv="refresh" content="0;URL='http://thetudors.example.com/'" />
隨着Javascript:
如果你能在項目中添加JavaScript中,我的建議是建立一個端點,以使用jQuery定期檢查或獲取:
胡安·安東尼奧
如果你正在使用REST
的電話,那麼這對你來說會很容易。
<script>
$(document).ready(function(){
setInterval(getWeather(),2000);
//Here get weather is a method and 2000 is numbers of milliseconds after which you want to update weather data
});
function getWeather(){
$.ajax({
type : 'GET'
url : 'Your url here'
success : function(data){
//set received data to your container
}
});
}
</script>
可能有用:https://en.wikipedia.org/wiki/Push_technology#Long_polling –
一個更復雜的方法將包括的WebSockets:http://stackoverflow.com/questions/10028770/in-what -situations-將-Ajax的長 - 短 - 輪詢待優選的環比HTML5的websock。我已經在我們的項目中使用了大約一年,雖然有一個學習曲線,但它相當好。 – bphilipnyc