Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
mike coffey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gary Mann
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic