javax.servlet.ServletException: 实例化 servlet 时出错 class servlet.DeleteData

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

我有这个 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.
    }
}

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>

我在启动 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)

这是怎么造成的,我该如何解决?

包名 package sevenet;DeleteData.java

中有错别字

要么在 DeleteData.java 中更正包名称,要么像这样更新 web.xml 中的包名称:

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

您忘记了 doGet() 上的@Override 注释并且 web.xml

中的 DeleteData servlet 程序包名称不正确