java.lang.ClassNotFoundException: HelloServlet at org.apache.catalina.loader.WebappClassLoader.loadClass

前端 未结 4 819
有刺的猬
有刺的猬 2021-01-06 15:38

I have a Hello World servlet in webapps/hello/WEB-INF/class/HelloServlet.class and I registered it as below in web.xml:



        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 15:42

    The main problem is that your servlet class doesn't have a package. Declare one.

    package com.example;
    
    public class HelloServlet extends HttpServlet {
    

    And when registering in web.xml, make sure you include the package:

    com.example.HelloServlet
    

    Also, your class file should be inside the /WEB-INF/classes directory, not /WEB-INF/class.

    webapps/hello/WEB-INF/classes/com/example/HelloServlet.class
    

提交回复
热议问题