0

I'm having a problem with tomcat 6 and redirection. My servlet creates a class that generates a file on the tomcat server. At the end of the servlet's post method I call the redirect method so that the user can download this file. The user is redirected and prompted to download the file. The problem is the file is stale. It's the file that was there before I started the tomcat server. I even tried sleeping the thread before the redirection. Any ideas why they are being redirected to this stale file that no longer exists?

I'm using eclipse to start a tomcat server.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String outputName = "XXX\\workspace\\BlahOnline\\WebContent\\Blah.xlsm";
    String redirect = "Blah.xlsm";
    response.sendRedirect(redirect);
} 

Edit: Nevermind, I found a better way to download the file using code in the servlet. This thread helped a lot: Download mp3 file from Tomcat server with Java servlet

4

2 回答 2

0

也许有类似 TTL (timeToLife) 的东西使服务器输出与几分钟前相同。如果 TTL 是一小时,它将输出相同的一小时。只有在这个小时之后,它才会更新答案文件。

看看你的 Tomcat 服务器的 TTL 配置。

于 2013-07-29T19:11:54.073 回答
0

我找到了一种从 tomcat 下载文件的更好方法。我使用 Streams 而不是将用户重定向到文件。这个线程帮了很多忙:Download mp3 file from Tomcat server with Java servlet

于 2013-07-29T20:23:47.977 回答