我有这个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)
这是如何引起的?如何解决?
答案 0 :(得分:1)
DeleteData.java
中的包名package sevenet;
中存在拼写错误
在 DeleteData.java 中更正软件包名称或更新 web.xml 中的软件包名称,如下所示:
<servlet>
<servlet-name>DeleteData</servlet-name>
<servlet-class>sevenet.DeleteData</servlet-class>
</servlet>
答案 1 :(得分:0)
您忘记了doGet()上的@Override注释,并且web.xml中的DeleteData servlet包名称不正确