servletsinstantiationservletexception

javax.servlet.ServletException: Error instantiating servlet class servlet.DeleteData


I have this servlet DeleteData.java

package sevenet;

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 java.io.IOException;
import java.io.*;
import java.sql.*;

@WebServlet("/deleteData")
public class DeleteData extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Some code.
    }
}

Which is registered as below in web.xml

<servlet>
    <servlet-name>DeleteData</servlet-name>
    <servlet-class>servlet.DeleteData</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>DeleteData</servlet-name>
    <url-pattern>/DeleteData</url-pattern>
</servlet-mapping>

I got error when starting the webapp:

javax.servlet.ServletException: Error instantiating servlet class servlet.DeleteData
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)

How is this caused and how can I solve it?


Solution

  • There is typo in package name package sevenet; in DeleteData.java

    Either correct package name in DeleteData.java or update the package name in web.xml like this:

    <servlet>
        <servlet-name>DeleteData</servlet-name>
        <servlet-class>sevenet.DeleteData</servlet-class>
    </servlet>