G:demo3srcmainjavacomexampledemo3>javac HelloServlet.java -classpath "C:Program FilesApache Software FoundationTomcat 10.0libservlet-api.jar"
HelloServlet.java:8: error: cannot find symbol
public class HelloServlet extends GenericServlet{
^
symbol: class GenericServlet
HelloServlet.java:10: error: cannot find symbol
public void service(ServletRequest servletRequest, ServletResponse servletResponse)
^
symbol: class ServletRequest
location: class HelloServlet
HelloServlet.java:10: error: cannot find symbol
public void service(ServletRequest servletRequest, ServletResponse servletResponse)
^
symbol: class ServletResponse
location: class HelloServlet
HelloServlet.java:11: error: cannot find symbol
throws ServletException, IOException {
^
symbol: class ServletException
location: class HelloServlet
HelloServlet.java:3: error: package javax.servlet does not exist
import javax.servlet.*;
^
HelloServlet.java:9: error: method does not override or implement a method from a supertype
@Override
^
6 errors
我做错了什么?CLASSPATH创建到servlet-api.jar文件btw在此处输入图像描述
Tomcat 10正在为servlet包使用新的jakarta.*
命名空间。您正在导入旧的javax.servlet.*
。只需将javax.servlet.
替换为jakarta.servlet.
,编译就可以了。