2014-10-27 77 views
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

我看穿thisthis线程,但它没有帮助我。

如何让这个servlet正常工作?

+2

您是否尝试导入缺失的类?它说它没有XmlOptions类。你可以在这个jar中找到它:http://www.java2s.com/Code/Jar/x/Downloadxmlbeansxmlpublic240jar.htm。尝试导入它,并再次尝试:) – 2014-10-27 15:04:30

回答

相关问题