0

I'm have a project that creates ms word document with apache poi. I'm trying to run my project .jsp page using servlet. These are my project start codes. I'm getting datas in my access database.

public static void Start(String SalesOrder, String type) throws SQLException, IOException {

  baslik[0]="ATA";  
  baslik[1]="LID";
  baslik[2]="PN";
  baslik[3]="QPE";
  baslik[4]="SV";
  baslik[5]="IS";
  baslik[6]="RS";
  baslik[7]="REP";
  baslik[8]="Defect";

  baslik2[0]="PN";
  baslik2[1]="NEW";
  baslik2[2]="REP";
  baslik2[3]="SV";
  baslik2[4]="Information Only";


    try {
        document = new XWPFDocument();
        start_page_1(SalesOrder,type);
        start_page_2(SalesOrder,type);
        header_footer(SalesOrder,type);
        if(type=="Gate_1")
        {
            summary(SalesOrder, type);
            eng_general(SalesOrder,type);
            oil_sys(SalesOrder,type);
            fuel_sys(SalesOrder,type);
            bleed_vlv(SalesOrder,type);
            bor_insp(SalesOrder,type);
            ext_parts(SalesOrder,type);
            fan_rotor(SalesOrder,type);
            lpc(SalesOrder,type);
            fan_case(SalesOrder, type);
            fbc(SalesOrder, type);
            ext_gear(SalesOrder, type);
            hps(SalesOrder, type);
            hpr(SalesOrder, type);
            diffuser(SalesOrder, type);
            combustor(SalesOrder, type);
            no4Bearing(SalesOrder, type);
            ngv(SalesOrder, type);
            hpt(SalesOrder, type);
            lpt(SalesOrder, type);
            tec(SalesOrder, type);
        }
        else if(type=="PDM")
            partoff(SalesOrder,type);
        else if(type=="SVR")
        {
            summary(SalesOrder, type);
            eng_general(SalesOrder,type);
            oil_sys(SalesOrder,type);
            fuel_sys(SalesOrder,type);
            bleed_vlv(SalesOrder,type);
            bor_insp(SalesOrder,type);
            ext_parts(SalesOrder,type);
            fan_rotor(SalesOrder,type);
            lpc(SalesOrder,type);
            fan_case(SalesOrder, type);
            fbc(SalesOrder, type);
            ext_gear(SalesOrder, type);
            hps(SalesOrder, type);
            hpr(SalesOrder, type);
            diffuser(SalesOrder, type);
            combustor(SalesOrder, type);
            no4Bearing(SalesOrder, type);
            ngv(SalesOrder, type);
            hpt(SalesOrder, type);
            lpt(SalesOrder, type);
            tec(SalesOrder, type);
            partoff(SalesOrder,type);
        }
        else
            sb72_0408(SalesOrder, type);
    } catch (InvalidFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
//baglanti= DriverManager.getConnection("jdbc:ucanaccess://"+db_file,db_username,db_password);
  //sorgu=baglanti.createStatement();
 //deneme=sorgu.executeQuery("SELECT * FROM TableRun");
    System.out.println("Process Completed"); 

}

My servlet codes like this

package Servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import access_read_and_write.access_connection;

/**
 * Servlet implementation class report_servlet
 */
@WebServlet("/report_servlet")
public class report_servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public report_servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String salesorder = request.getParameter("salesOrder");
        String radio=request.getParameter("a");
        String message = null;
        if(salesorder== null) {
            message="Wrong Sales Order Defined. Please Check your Sales Order"; 
       } 
       else {

               if(radio.equals("PDM Report"))
               {
                   try {
                    access_connection.Start(salesorder,"PDM");
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                   message=salesorder+" PDM Report was saved on your D: Drive.";
               }
               else if(radio.equals("Gate 1 Report"))
               {
                   try {
                    access_connection.Start(salesorder,"Gate_1");
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                   message=salesorder+" Gate 1 Report was saved on your D: Drive.";
               }
               else if(radio.equals("Shop Visit Report"))
               {
                   try {
                    access_connection.Start(salesorder,"SVR");
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                   message=salesorder+" Shop Visit Report was saved on your D: Drive.";
               }
               else if(radio.equals("SB72-0408 Report"))
               {
                   try {
                    access_connection.Start(salesorder,"SB72_0408");
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                   message=salesorder+" SB72-0408 Report was saved on your D: Drive.";
               }




       }
        request.setAttribute("message", message);
        request.getRequestDispatcher("pdm.jsp").forward(request, response);
    }

}

No errors in sight but when I run project, I'm getting this error.

java.lang.ClassNotFoundException: org.apache.poi.POIXMLTypeLoader
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1360)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1182)
    at org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1$Factory.newInstance(Unknown Source)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentCreate(XWPFDocument.java:305)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:150)
    at access_read_and_write.access_connection.Start(access_connection.java:200)
    at Servlet.report_servlet.doPost(report_servlet.java:63)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

In my .jsp page, I have textbox, 4 radio button and 1 submit button. I'm writing data in text box then I'm choosing which report will create and then I'm clicking submit button. It was working correctly until today. I added radio button in my .jsp page and then I have edited my servlet and it started gives me this error. This is my libraries enter image description here

7
  • Are there multiple versions of the jar in your classpath? Commented Dec 23, 2019 at 11:39
  • @Amanjangra I have these .jar's in my libraries. poi-ooxml-4.1.0.jar,ooxml-schemas-1.4.jar Commented Dec 23, 2019 at 11:51
  • I think this has something to do with how you defined your schema. Can you add that bit? Commented Dec 23, 2019 at 12:23
  • I add my libraries folder. Commented Dec 23, 2019 at 13:35
  • are you able to use maven? Commented Dec 23, 2019 at 13:51

3 Answers 3

2

It appears as if there is a version mismatch between dependent jars or a single jar with multiple versions are present in the classpath. Delete all jars, go to official Apache POI download page and download the zipped file containing all the jars. All jars would be of the same version. Add those jars to your project and check.

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

1 Comment

I can't determine a version mismatch, I tried it new jars but still got this error. It nonsense, at the morning it was running correctly then I changed servlet and it gives me this error.
0

I had a similar issue, it seems that in new versions of Apache POI, a reference to org.apache.poi.POIXMLTypeLoader persists, in new versions this class was moved to org.apache.poi.ooxml.POIXMLTypeLoader

The solution that I applied is to use version 3.17 of Apache POI

Comments

-1

Try to import the org.apache.poi.POIXMLTypeLoader library. Some jar is probably missing or misplaced. Here is one of the options: https://jar-download.com/artifacts/org.apache.poi/poi-ooxml/3.17/source-code/org/apache/poi/POIXMLTypeLoader.java

1 Comment

Importing has nothing to do with class loading at runtime!

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.