File access from Servlet apps.

Jeff Duska is forgetting a couple of things that many Servlet/JSP developers (myself included) often forget. He is forgetting the distributed nature of Servlet apps and he is forgetting the WAR.

Someday, when your app becomes incredibly popular, you might find that you need to distribute the load across multiple worker processes on multiple computers. All the major app servers support this, does your app? In a distributed configuration, if your app writes a file to the file-system on one computer, you won't be able to get to that file on another computer. If you want all instances of your app to share a file, then this is a problem. If you are just writing a simple little temporary file, which sounds like Jeff's case, then this is generally not a problem.

Even if you are only writing a temporary file, you still don't want to write it inside your Servlet context. When your app is packaged in a WAR file, may not be able to open files inside the Servlet context. If you are just writing a temporary file, it might be better to use one of the static java.io.File.createTempFile() methods to get a file.



Like this post?  del.icio.us Bookmark it   |   submit to dig digg.com Digg it   |   slashdot Slashdot it   |   technorati See who links to it

Comments:

Post a Comment:
  • HTML Syntax: Allowed

This work is licensed under a Creative Commons License.
Copyright 2002-2007, David M Johnson (dave.johnson at rollerweblogger.org)

This is a personal weblog, I do not speak for my employer.