• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Upload File Servlet

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I want to upload a simple file from a html to a webserver running on apache tomcat.
I used html tag <input type="file" name="upload_file" /> to select and post my request to servlet.

In the servlet used the ServletInputStream of the request to write the bytes to any particular file. The file is getting created in the server but it's content seems to be missing.

Can anyone tell me what is wrong with my approach ?? Any help is truely appreciable.

Uploading Servlet portion

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Handling HTTP file uploads is way more complicated that you think it is. A library like Apache Commons FileUpload makes it real easy, though.
 
Ramesh Sahu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Handling HTTP file uploads is way more complicated that you think it is. A library like Apache Commons FileUpload makes it real easy, though.



Thanks for the reply....

Actually I was expecting the reason behind it. I have a stream of data , then why can't I direct it into any destination???
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because the stream of data contains other data in addition to the actual file contents. Under the "specification URLs" link in my signature you can find the HTTP file upload spec - it's not trivial!
 
Ramesh Sahu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Because the stream of data contains other data in addition to the actual file contents. Under the "specification URLs" link in my signature you can find the HTTP file upload spec - it's not trivial!



Thanks a lot . It seems to clear the air .

 
Die Fledermaus does not fear such a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic