HTML File Upload using enctype=multipart/form-data in form?

Discussion in 'HTML' started by Matt, Oct 12, 2004.

  1. Matt

    Matt Guest

    Should we use enctype=multipart/form-data in the form, I know it is recommended
    if the form has <input type="file">. My form has <input type="file"> and other
    html controls.

    I tried the following,

    form.html
    =========
    <FORM NAME="InputForm" ACTION="test.jsp" METHOD="POST" enctype=multipart/form-data>
    <P><input type=text name="name" size=80>
    <P><input type=file name="filename" size=80>
    <P><input type="submit" value="Upload File Test">
    </FORM>

    test.jsp
    =========
    <p><%= "filename = " + request.getParameter("filename") %>
    <p><%= "name = " + request.getParameter("name") %>


    It will output
    filename = null
    name = null

    I don't understand why, but if i remove enctype=multipart/form-data in the form,
    then I am able to get the data.

    Please advise. Thanks!!
    Matt, Oct 12, 2004
    #1
    1. Advertising

  2. Matt wrote:

    > Should we use enctype=multipart/form-data in the form, I know it is
    > recommended if the form has <input type="file">.


    If you have file inputs - yes.

    > form.html
    > =========
    > <FORM NAME="InputForm" ACTION="test.jsp" METHOD="POST"
    > enctype=multipart/form-data>


    Try the validator. I'm pretty sure that you need to quote attribute values
    which include "/" characters.

    > <P><input type=file name="filename" size=80>


    > <p><%= "filename = " + request.getParameter("filename") %>


    File inputs upload files, not file names. NULL is probably what happens when
    you implicitly cast request.getParameter("filename") to a string (when its
    a file). You'd probably be better finding a Java group to ask this type of
    question.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Oct 12, 2004
    #2
    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. Matt
    Replies:
    8
    Views:
    142,318
    zeeshanakhter2009
    May 26, 2012
  2. Duncan
    Replies:
    0
    Views:
    1,453
    Duncan
    Feb 24, 2006
  3. Replies:
    1
    Views:
    1,791
    Alexey Smirnov
    Apr 21, 2008
  4. David Lozzi

    Using <form ... enctype="multipart/form-data">

    David Lozzi, Aug 12, 2003, in forum: ASP General
    Replies:
    5
    Views:
    321
    Martin CLAVREUIL
    Aug 12, 2003
  5. Kevin DeValck
    Replies:
    1
    Views:
    723
    7stud --
    May 17, 2011
Loading...

Share This Page