This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes What is the best way to process a file from the clients local machine? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "What is the best way to process a file from the clients local machine?" Watch "What is the best way to process a file from the clients local machine?" New topic
Author

What is the best way to process a file from the clients local machine?

mike coffey
Greenhorn

Joined: Oct 16, 2003
Posts: 2
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.
Gary Mann
Ranch Hand

Joined: Jun 05, 2003
Posts: 37
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.
mike coffey
Greenhorn

Joined: Oct 16, 2003
Posts: 2
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.
Sanjeev Kaushik
Ranch Hand

Joined: Aug 01, 2002
Posts: 105
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.


Sanjeev Kaushik
Gary Mann
Ranch Hand

Joined: Jun 05, 2003
Posts: 37
You probably already have this, but the link for various Jason Hunter / O'Reilly classes including the file upload is:
http://www.servlets.com/cos/index.html
Gary
Praveen Garimella
Greenhorn

Joined: Jul 17, 2003
Posts: 5
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


Praveen Garimella
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the best way to process a file from the clients local machine?
 
Similar Threads
Download a file from the server using Java Servlet
Tomcat 5 always asks for login & password-HELP
PLEASE HELP
FTP file from Local to Remote Machine
Compiling on a network.