如何从servlet中读取csv文件的内容

时间:2015-01-29 13:13:32

标签: java jsp csv servlets

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数据的连接已终止。

0 个答案:

没有答案