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

M

Matt

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!!
 
D

David Dorward

Matt said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top