keshet
keshet

Reputation: 1826

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?

Upvotes: 0

Views: 3883

Answers (1)

timguy
timguy

Reputation: 2582

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).

Upvotes: 2

Related Questions