我不知道如何使用 getParts()
来保存参数。
我正在尝试传递 4-5 个文本类型的输入以及一个图像文件。我想将参数检索到字符串中,这样我就可以将它们添加到数据库中,并将图像以 blob 格式保存在数据库中(而不是在服务器目录中)。
任何帮助将不胜感激。提前致谢
<form class="form-signin" action="createAlbum"
method="post" enctype="multipart/form-data" role="form">
<h2 class="form-signin-heading">
Add details to create an Album.
</h2>
<input type="text" name="aname"
class="form-control" placeholder="Album Name" required>
<input type="text" name="artists"
class="form-control" placeholder="Artist" required>
<input type="date" name="rdate"
class="form-control" placeholder="Release Date" required >
<input type="text" name="type"
class="form-control" placeholder="Genre" required >
<input type="text" name="price"
class="form-control" placeholder="Price">
<input type="file" name="picture"
class="form-control" placeholder="Picture" required >
<button class="btn btn-lg btn-primary btn-block"
type="submit">Add Album</button>
</form>
最佳答案
你可以试试 apache FileUpload
http://commons.apache.org/proper/commons-fileupload/using.html
然后你可以像这样处理你的多部分请求
// Process the uploaded items
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext()) {
FileItem item = iter.next();
if (item.isFormField()) {
processFormField(item);
} else {
processUploadedFile(item);
}
}
关于java - 如何保存从多部分表单传递给 servlet 的多个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21491551/