• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic