• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Upload File Servlet

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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: 43016
76
  • Mark post as helpful
  • send pies
  • 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
  • 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: 43016
76
  • Mark post as helpful
  • send pies
  • 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
  • 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 .

 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic