0
我想將excel文件上傳到servlet,從中獲取數據,然後將此數據發送到數據庫。將Excel文件上傳到servlet並從中獲取數據
而我一開始就卡住了:上傳文件。
從文件中獲取數據,我想使用Apache POI,這裏是我的代碼:
System.out.println("entered Import.java");
Part filePart = request.getPart("import");
System.out.println("filePart: "+filePart);
FileInputStream inputStream = (FileInputStream) filePart.getInputStream();
System.out.println("inputStream: "+inputStream);
Workbook book = WorkbookFactory.create(inputStream);
Sheet sheet = book.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
System.out.println("row: "+row+", cell value: "+cell.getRichStringCellValue().getString());
}
}
inputStream.close();
這段代碼的輸出:
entered Import.java
filePart: [email protected]
inputStream: [email protected]
Servlet.service() for servlet [Import] in context with path [/Management] threw exception [Servlet execution threw an exception] with root causejava.lang.ClassNotFoundException: org.apache.xmlbeans.XmlOptions
的UI部分SAPUI5框架和here it is。
如何讓這個servlet正常工作?
您是否嘗試導入缺失的類?它說它沒有XmlOptions類。你可以在這個jar中找到它:http://www.java2s.com/Code/Jar/x/Downloadxmlbeansxmlpublic240jar.htm。嘗試導入它,並再次嘗試:) – 2014-10-27 15:04:30