JSP File
-------------
<form method="post" id="bulk-form" action="/pc/upload" enctype="multipart/form-data">
<input type="hidden" name="product" value="${param.product}" />
<input type="file" multiple name="fname">
<input type="submit" class="btn red-btn" value="SUBMIT"/>
</form>
Servlet
-----------
String param = request.getParameter("product");
DiskFileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
try {
// Parse the request to get file items.
List<FileItem> fileItems = upload.parseRequest(request);
System.err.println("Got fileItems "+fileItems);
}
catch(Exception e){
}
在上面的代码中,request.getParameter("product")
返回正确的输出,但fileItems
为空。
如果未使用隐藏表单,则request.getParameter("product")
会显示multipart
数据的连接已终止。