commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rhino" <rhi...@sympatico.ca>
Subject [FileUpload] Testing for existence of file
Date Tue, 21 Dec 2004 00:50:26 GMT
I'm just polishing my first servlet that uses FileUpload and I'd like to ask
the experts how they're handling one situation that I encountered in my
testing.

While the normal (sensible?) way to do a download is to click the browse
button, then use the file dialog to find and select the file you want to
upload to the server, I noticed that it is possible for the user to simply
type in a file name in the input field. Unfortunately, that means the user
can type the name of a file that doesn't exist.

I would like my servlet to handle that situation gracefully: if a user
enters a file name that doesn't exist, I want to tell the user that this
happened and let them try again. What is the best way to detect that the
file name specified in the list of items does not exist on the user's PC?

I tried using the exists() method in the File class and it worked fine as
long as I was uploading from my PC to somewhere else on my PC. However, when
I put the servlet on our server, this logic mistakenly told me that a file
which certainly DID exist on my PC didn't exist; I assume it was looking on
the server to see if that file was where I'd specified in the upload.

How are the experts handling this problem? I don't see anything in the
FileUpload API that specifically tests for the existence of the file on the
user's machine so I'm curious what people are doing.

Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message