0

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?

1

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

well, this is embaressing for me. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.