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?

Community
  • 1
  • 1
keshet
  • 1,716
  • 5
  • 27
  • 54
  • 2
    Did you try to import the class you are missing? It says it doesn't have the XmlOptions class. You can find it in this jar : http://www.java2s.com/Code/Jar/x/Downloadxmlbeansxmlpublic240jar.htm. Try to import it and try again :) – Cesar Villasana Oct 27 '14 at 15:04

1 Answers1

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

Community
  • 1
  • 1
timguy
  • 2,063
  • 2
  • 21
  • 40