用多部分发送附加数据 [英] Sending additional data with multipart
问题描述
apache-commons-fileupload
从 client
到 server
。(使用 JSP
和 Servlet
)。 JSP / HTML
< form method =POSTaction =GetFileenctype =multipart / form-data>
< input type =filename =datafile>
< input type =textname =text1>
< input type =submitvalue =Next>
< / form>
Servlet:GetFile
System.out.println(request.getParameter(text1));
我可以将文件上传到服务器,但是我无法获得 text1
在 servlet
(我得到 null
value text1
在 servlet
中),我需要这个 textfield
in在上传到服务器
时提交一些额外的信息。 enctype =multipart / form-data
表单的选项不允许其他
表单数据被引用?如果它不允许它,那么我有什么其他的选择发送这个额外的 textfield
到服务器
。
是
enctype =multipart / form-data
选项不允许其他
格式的数据submited?如果它不允许它,那么
其他选项是什么我必须发送这个额外的文本字段到服务器。
不,使用 enctype =multipart / form-data
没有问题。你可以得到其他字段,然后在这样的形式文件。
或者在我的代码中有任何其他问题?
是的,就像现在一样。在使用 enctype =multipart / form-data
时,不能通过使用 request.getParameter(name);
。在使用它时,表单字段不可用作请求的参数,它们被包含在流中,所以你不能以正常的方式得到它。您可以在使用commons-fileupload的文档中找到一种方法,在部分处理上传的内容。
I am using apache-commons-fileupload
to get file from client
to the server
.(using JSP
and Servlet
).
JSP/HTML
<form method="POST" action="GetFile" enctype="multipart/form-data">
<input type="file" name="datafile">
<input type="text" name="text1">
<input type="submit" value="Next">
</form>
Servlet: GetFile
System.out.println(request.getParameter("text1"));
I am able to upload the file to the server, but I am not able to get the value of text1
in the servlet
(I am getting null
value of text1
in the servlet
), I need this textfield
in the form to submit some additional information while uploading it to the server
.
- Is
enctype="multipart/form-data"
option of form doesn't allow other form data to be submited? if it doesn't allow it then what are the other options I have to send this additionaltextfield
to theserver
. - Or is there any other problem in my code?
Is
enctype="multipart/form-data"
option of form doesn't allow other form data to be submited? if it doesn't allow it then what are the other options I have to send this additional textfield to the server.
No there is no issue with using enctype="multipart/form-data"
. You can get other fields then file in such form.
Or is there any other problem in my code?
Yes, as for now. While using enctype="multipart/form-data"
you can not directly get parameters by using request.getParameter(name);
. While using it, form fields aren't available as parameter of the request, they are included in the stream, so you can not get it the normal way. You can find a way to do this in the docs of using commons-fileupload, under the section Processing the uploaded items.
这篇关于用多部分发送附加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!