Servlet:部署工件时出错。请参阅服务器日志了解详细信息

初学Servlet,在启动Tomcat时,出现下面错误:

 下面是Servlet类的源代码

package MyServlet;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;

import java.io.IOException;
@WebServlet(urlPatterns="Test_Servlet",loadOnStartup = -1)
public class Test_Servlet implements Servlet {
    public Test_Servlet(){
        System.out.println("Servlet对象被创建了");
    }
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        System.out.println("初始化Servlet对象");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("具体的业务逻辑代码,该servlet的内存地址:"+this);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("servlet被销毁了");
    }
}

仔细再看,原来是@WebServlet的urlPatterns参数写错了少了个/,也就是得将Test_Servlet改为

/Test_Servlet

你可能感兴趣的:(报错解决,servlet,服务器,java)