在我的servlet中,我生成了一个json文件并将其写入我的WebContent
文件夹中。Apache Tomcat - 读取生成的旧文件
try (FileWriter file = new FileWriter("c:/users/user/workspace/poum/WebContent/answer.json")) {
file.write(answerJSON);
}
而在我的jsp页面,我调用该文件answer.json
这样的:
d3.json("answer.json", function(error, json) {
if (error) throw error;
的问题是,每当我运行的文件,它总是读取旧json
文件创建。我检查了answer.json
,并更新了最新的内容,所以我认为这个问题不在servlet中。
我试图在IDE和浏览器中运行该文件,都给出了相同的结果。 我读到tomcat中的TTL配置可能是原因,但我没有改变任何东西,默认的TTL是5秒。
检查https://stackoverflow.com/questions/24325220/d3-json-setup-cache-to-false或https://stackoverflow.com/questions/13053096/avoid-data-caching-when -using-d3-text – user7294900
@ user7294900尝试在html头设置no-cache,但仍然无法正常工作。 –
添加到网址随机数为:'answer.json?' + Math.floor(Math.random()* 1000) – user7294900