2017-09-10 107 views
0

在我的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秒。

+0

检查https://stackoverflow.com/questions/24325220/d3-json-setup-cache-to-false或https://stackoverflow.com/questions/13053096/avoid-data-caching-when -using-d3-text – user7294900

+0

@ user7294900尝试在html头设置no-cache,但仍然无法正常工作。 –

+0

添加到网址随机数为:'answer.json?' + Math.floor(Math.random()* 1000) – user7294900

回答

0

清除Work文件夹并重新启动tomcat服务器。编译工作文件夹中存在的JSP文件。

<tomcat_directory/work> 
+0

我已经完成了这项工作,但每次重新启动服务器时都会发生这种情况。通常前两次都可以,但在此之后它不起作用。 –