简体   繁体   中英

Upload Excel file to servlet and get data from it

I'm trying to upload excel file to a servlet, get data from it and then send this data to a database.

And I'm stuck at the very beginning: uploading the file.

To get data from the file, I want to use Apache POI, and here is my code:

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();

The output of this code is:

entered Import.java
filePart: org.apache.catalina.core.ApplicationPart@bc6f13
inputStream: java.io.FileInputStream@532048c5
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

The UI part is SAPUI5 framework and here it is .

I looked through this and this threads, but it didn't help me.

How do I get this servlet to work?

You are missing the jars in your web application which are containing the XmlOptions class.

See the following reply in ( java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlOptions ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM