title: Reading Docx file content in jsp using apache POI org.apache.jasper.JasperException: Unable to compile class for JSP:
body: <p>Hi I want to show Microsoft docs content to the web page using Apache POI library</p>
  
  <p>This is working fine with as a java application. </p>
  
  <p>but application is throwing exception on jsp</p>
  
  <p>PS </p>
  
  <p>Below is my work so far</p>
  
  <pre><code>&lt;%@ page import="java.io.*" %&gt;
  &lt;%@ page import="org.apache.poi.openxml4j.opc.OPCPackage" %&gt;
  &lt;%@ page import="org.apache.poi.xwpf.extractor.XWPFWordExtractor" %&gt;
  &lt;%@ page import="org.apache.poi.xwpf.usermodel.XWPFDocument" %&gt;
  &lt;body&gt;
  &lt;form name="form1" method="get" action="FileServlet"
      style="height: 78px;"&gt;
      &lt;input type="file" name="xls_filename" align="top"
          onchange="form1.submit()"&gt;
  &lt;/form&gt;
  &lt;%
      String filename = request.getParameter("xls_filename");
  
      if (filename != null &amp;&amp; !filename.equals("")) {
  %&gt;
  &lt;br&gt;You chose the file
  &lt;%=filename%&gt;.
  
  &lt;br&gt;It's contents are:
  &lt;%
      InputStream fs = null;
          String fileData;
  
          XWPFWordExtractor extractor = null;
  
          try {
              fs = new FileInputStream(filename);
  
              XWPFDocument hdoc = new XWPFDocument(OPCPackage.open(fs));
  
              extractor = new XWPFWordExtractor(hdoc);
  
              fileData = extractor.getText();
              System.out.println(fileData);
              // document.add(new Paragraph(fileData));
              System.out.println(" pdf document created");
          } catch (IOException e) {
              System.out.println("IO Exception");
              e.printStackTrace();
          } catch (Exception ex) {
              ex.printStackTrace();
          } finally {
              //  document.close();
          }
  %&gt;
  &lt;%
      }
  
  %&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code> at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
      at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
      at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
      at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>above is complete stack trace and errors shown as:</p>
  
  <p>An error occurred at line: 40 in the jsp file: /index.jsp
  XWPFDocument cannot be resolved to a type</p>
  
  <p>An error occurred at line: 40 in the jsp file: /index.jsp
  OPCPackage cannot be resolved</p>
  
  <p>An error occurred at line: 42 in the jsp file: /index.jsp
  XWPFWordExtractor cannot be resolved to a type</p>