I am fairly green as far as Java goes. However, I am writing a servlet that will take in an input file from the user's local machine. I do not need to save this file on the server side. I just want to process the rows within the file.
Mike, Since servlets run on the server the only way to process the file is to upload it, process it and then return the results as HTML or as a downloaded file. If you want to process on the client, then check out signed applets. Frankly, I think these have limited use as the user must have the correct JVM version to run applets and must grant the appropriate permissions.
Joined: Oct 16, 2003
Thanks for the input Gary. I just picked up Java Servlet Programming by Jason Hunter. I'm looking at his MultiPart class. Hopefully this will do the job. I do have a question though, do I have to save the file on the server side when it's uploaded or can I just process the content? I don't want the user to be able to corrupt a valid file on the server.
When client uploads the file, it is just like a post request. Servlet can get this file from the input stream. It means you are first reading the file, then only its up to you if you want to serialize it. You can get lots of FileUploadSerlvet examples on the net. Once you see the code, every thing would be clear.
Mike, Once you get hold of the input stream you have the flexibility of processing the records in memory or on the disk, this depends on the size of the file. If it is a huge file to be processed then serialize it. If its a tiny file then dont serialize it. But serializing the file on the server is transperent for the client. I dont think there is a way for u'r client to know wheather you are serializing the file or processing it in the memory. Please take care of checking the file size thought, people can fill up you memory by uploading large files