Go Back   Velocity Reviews > Newsgroups > HTML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

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

 
Thread Tools Search this Thread
Old 10-12-2004, 08:34 PM   #1
Default HTML File Upload using enctype=multipart/form-data in form?


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
  Reply With Quote
Old 10-12-2004, 09:17 PM   #2
David Dorward
 
Posts: n/a
Default Re: HTML File Upload using enctype=multipart/form-data in form?

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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump