编译时错误:包javax.servlet不存在导入javax.servlet。*

我将类路径设置如下: CLASS_PATH:C:\ Program Files \ Apache Software Foundation \ Tomcat 10.0 \ lib; C:\ Program Files(x86)\ Java \ mysql-connector.jar; C:\ Program Files(x86)\ Java \ sqljdbc_8.2 \ enu \ mssql-jdbc-8.2.0.jre8.jar;

而且我还尝试在编译时使用jar文件:- java -cp C:\ Program Files \ Apache Software Foundation \ Tomcat 10.0 \ lib \ servlet-api.jar Hello.java

java -cp“ C:\ Program Files \ Apache Software Foundation \ Tomcat 10.0 \ lib \ servlet-api.jar” Hello.java

java -cp。; C:\ Program Files \ Apache Software Foundation \ Tomcat 10.0 \ lib \ servlet-api.jar Hello.java

java -cp“。;”“ C:\ Program Files \ Apache Software Foundation \ Tomcat 10.0 \ lib \ servlet-api.jar” Hello.java

java -cp C:\ Program Files \ Apache Software Foundation \ Tomcat 10.0 \ lib \ servlet-api.jar;。你好

java -cp“ C:\ Program Files \ Apache Software Foundation \ Tomcat 10.0 \ lib \ servlet-api.jar”;。你好

我也尝试用classpath替换-cp,但是每次仍然出现以下错误:- C:\ Program Files \ Apache Software Foundation \ Tomcat 10.0 \ webapps \ 16 servlet \ WEB-INF \ classes> javac -cp。; servlet-api.jar;你好 Hello.java:2:错误:程序包javax.servlet不存在 导入javax.servlet。*; ^

Hello.java:3:错误:找不到符号 公共类Hello实现Servlet                               ^   符号:Servlet类

Hello.java:5:错误:找不到符号         公共无效init(ServletConfig sc)引发ServletException                          ^   符号:类ServletConfig   位置:班你好

Hello.java:5:错误:找不到符号         公共无效init(ServletConfig sc)引发ServletException                                                  ^   符号:类ServletException   位置:班你好

Hello.java:9:错误:找不到符号         公共ServletConfig getServletConfig()                ^   符号:类ServletConfig   位置:班你好

Hello.java:13:错误:找不到符号         公共无效服务(ServletRequest req,ServletResponse res)抛出ServletException                             ^   符号:类ServletRequest   位置:班你好

Hello.java:13:错误:找不到符号         公共无效服务(ServletRequest req,ServletResponse res)抛出ServletException                                                ^   符号:类ServletResponse   位置:班你好

Hello.java:13:错误:找不到符号         公共无效服务(ServletRequest req,ServletResponse res)抛出ServletException                                                                           ^   符号:类ServletException   位置:班你好 8个错误

我的Hello.java Servlet文件:-

    import java.io.*;
    import javax.servlet.*;

public class Hello implements Servlet
{
    public void init(ServletConfig sc)throws ServletException
    {

    }
    public ServletConfig getServletConfig()
    {
        return null;
    }
    public void service(ServletRequest req,ServletResponse res)throws ServletException
    {
        String name=req.getParameter("name");
        PrintWriter out=res.getWriter();
        out.println("Hello "+name);
    }
    public String getServletInfo()
    {
        return null;
    }
    public void destroy()
    {

    }
}

tbh我也在netbeans IDE上尝试了其他Servlet Java程序,并且运行良好,但是即使在搜索并尝试了所有可能的解决方案之后,我也无法自己明确配置它,伙计们请帮助我解决它。