DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31556>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=31556

getResourceAsStream caches a file but fails to note that it has been updated

           Summary: getResourceAsStream caches a file but fails to note that
                    it has been updated
           Product: Tomcat 5
           Version: 5.0.28
          Platform: PC
        OS/Version: Windows 9x
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Catalina
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


1. The sample servlet (see below) calls getResourceAsStream to read the first
line of a text file (eg, "abc") and outputs it.
2. I update the text file to change its content (eg, "def").
3. Reload the web page but it is still displaying the old file content ("abc").
It means the servlet is not getting the new file content.
4. However, there is a twist. If I save the file again (eg, add a space, delete
the space and save again) and reload the web page, then it will display the new
file content ("def").

The sample servlet is shown below. The text file is /WEB-INF/test.txt.

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet {
        protected void doGet(
                HttpServletRequest request,
                HttpServletResponse response)
                throws ServletException, IOException {
                PrintWriter writer = response.getWriter();
                BufferedReader reader =
                        new BufferedReader(
                                new InputStreamReader(
                                        getServletContext().getResourceAsStream(
                                                "/WEB-INF/test.txt")));
                try {
                        writer.println(reader.readLine());
                } finally {
                        reader.close();
                }
        }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to