我已经关闭了缓存并使用javascript从jsp页面中的rest调用中手动检索状态。当然,每个人都喜欢它(Chrome,FireFox,Safari,Opera),除了IE 8-11。
大部分工作由getStatus()完成。这使用XMLHttpRequest从REST调用中检索一组json状态。它解析json并将状态复制到td标记的innerHTML。我使用setInterval()每5秒执行一次。
我使用靠近jsp顶部的Cache-Control,Pragma和Expires标头关闭缓存。
症状是状态永远不会更新。
以下是代码:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
//tell browsers and proxy servers not to cache this page
if ("HTTP/1.1".equals(request.getProtocol()))
{
response.setHeader("Cache-Control", "no-cache");
}
response.setHeader("Pragma","no-cache" );
response.setDateHeader("Expires", 0);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Application Title</title>
<link rel="stylesheet" type="text/css" href="<c:out value="${pageContext.request.contextPath}"/>/css/Admin.css" />
<script type="text/javascript">
// need enough time for jbehave to parse the page
var REFRESH = 5000; // 5 seconds
// Update status after 5 seconds has elapsed.
setInterval("jobStatus();", REFRESH);
function jobStatus() {
getStatus();
}
function getStatus() {
var xhttpRequest = getXMLHttpRequest();
xhttpRequest.open("GET", "<c:out value="${pageContext.request.contextPath}"/>/admin/resyncPhs/getstatus", true);
xhttpRequest.onreadystatechange = function() {
if (xhttpRequest.readyState === 4) {
if (xhttpRequest.status === 200) {
var json = xhttpRequest.responseText;
var parsed = JSON.parse(json);
document.getElementById("status").innerHTML = parsed.status;
document.getElementById("progress").innerHTML = parsed.progress;
}
}
};
xhttpRequest.send(null);
}
function getXMLHttpRequest() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
</script>
</head>
<body onLoad="jobStatus();">
<table class="resyncBodyTable">
<tr>
<td />
<td>Labels:</td>
<td id="status">${status}</td>
<td id="progress">${progress}</td>
</tr>
</table>
</body>
</html>
任何线索?
答案 0 :(得分:3)
IE需要比其他浏览器更多的说服力:
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma","no-cache");