html多部分表单中输入文本字段的值 [英] values of input text fields in a html multipart form
问题描述
我在Apache服务器端应用程序中使用Apache Commons FileUpload,该应用程序具有包含字段的html表单:
$ b
-
fied将
填入
目标邮箱的电子邮件地址
-
带有发件人邮件的邮件文本
> - a
<输入类型=文件...
用于上传照片的字段。
我可以接收上传的文件(作为流),但我如何访问1)和2)表单值(由应用程序的用户完成)?
非常感谢,
Aurel
使用FileItemIterator迭代请求中的项目。迭代器的next()方法返回一个FileItemStream(不是FileItem)。打开该对象上的流,并将其转换为如下所示的字符串:
$ p $ import org.apache.commons.fileupload.util。流;
...
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
String name = item.getFieldName();
String value = Streams.asString(stream);
其他答案提供的getString方法是FileItem接口上的一个方法。 $ b
I use Apache Commons FileUpload in a java server-side app that has a html form with fields :
a destination fied that will be filled with email address of the destination mailbox
a message text with a message of the sender
- a
<input type=file ...
field for uploading a photo. I can receive uploaded file (as a stream) but how I can access 1) and 2) form values (completed by the user of app)? Many thanks, Aurel
I am guessing you are using a FileItemIterator to iterate the items in the request. The iterators next() method returns a FileItemStream (not a FileItem). Open the stream on that object and turn it into a string like this:
import org.apache.commons.fileupload.util.Streams;
...
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
String name = item.getFieldName();
String value = Streams.asString(stream);
The getString method suggested by other answers is a method on the FileItem interface.
这篇关于html多部分表单中输入文本字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!