binary upload of a file with servlet

Discussion in 'Java' started by Astrid Wagner, Aug 18, 2003.

  1. Hi,
    I want to write a servlet that uploads a file.
    I read some about that the content type has to be multipart/formdata but

    I would like to have a little example on this.
    Can someone help?
    Thanks.
    Astrid
    Astrid Wagner, Aug 18, 2003
    #1
    1. Advertising

  2. Astrid Wagner wrote:

    > Hi,
    > I want to write a servlet that uploads a file.
    > I read some about that the content type has to be multipart/formdata but
    >
    > I would like to have a little example on this.
    > Can someone help?
    > Thanks.
    > Astrid


    You could use http://jakarta.apache.org/commons/fileupload/, it does what
    you need.
    --
    mvg,
    Christophe Vanfleteren
    Christophe Vanfleteren, Aug 18, 2003
    #2
    1. Advertising

  3. Thanks for the link!
    The problem I have is that i do not exactly know how to write a servlet
    that serves a source for the file upload. Here my problem:
    I have a html page that has a input field "file" that will contain the file
    name to upload
    and a submit button whose action will have to result in writing the file to a
    server side
    location and display a page accordingly.
    The html page:
    <form method='POST' ACTION='http://<machine>:<port>/UploadWebFilePage'
    enctype='multipart/form-data'>
    <input type='hidden' name='page' value='upload_onlinefile_form'>
    <input type='hidden' name='next_page' value='save_onlinefile_info'>
    <input type='hidden' name='id' value='10612'>
    <input type='hidden' name='target' value='edit_view'>
    <h2>Upload file for: TestX Rev. 2.0</h2>
    <div>
    <input type='hidden' name='view_id' value='7520'>

    <b>View:</b> one_pager<br>
    <br>
    File to upload: <input type='file' name='file' size='50'><br>
    <br>
    <br>
    <input type='submit' name='submit' value='Upload File'>
    </div>
    </form>

    How can the UploadWebFilePage servlet read the data in the given file into
    another file and create a response that
    is of "text/html" MIME type meaning a regular html page? I do not need a
    "Save to disk" window appearing asking me to choose where to store
    the file because I will evaluate the destination automatically depending on
    some of the above hidden input fields.
    Thanks.
    Astrid



    Christophe Vanfleteren wrote:

    > Astrid Wagner wrote:
    >
    > > Hi,
    > > I want to write a servlet that uploads a file.
    > > I read some about that the content type has to be multipart/formdata but
    > >
    > > I would like to have a little example on this.
    > > Can someone help?
    > > Thanks.
    > > Astrid

    >
    > You could use http://jakarta.apache.org/commons/fileupload/, it does what
    > you need.
    > --
    > mvg,
    > Christophe Vanfleteren
    Astrid Wagner, Aug 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FyYXY=?=

    Upload a file without file Upload control - ASP.Net

    =?Utf-8?B?U2FyYXY=?=, Aug 2, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,424
    Bruce Barker
    Aug 3, 2005
  2. Paul  Smith
    Replies:
    1
    Views:
    3,154
    Paul Smith
    Nov 17, 2003
  3. circuit_breaker
    Replies:
    2
    Views:
    1,989
    Jack Jia
    Apr 4, 2004
  4. DiscoStu
    Replies:
    1
    Views:
    563
  5. Replies:
    3
    Views:
    8,713
    Ross Bamford
    Nov 5, 2005
Loading...

Share This Page