初入servlet:Allocate exception for servlet

时间:2022-03-15 16:36:55
老板,来一碗错误垫垫肚子!
如果以下几个错误都符合,估计就是这个原因了。
页面报错如下:

java.lang.NoClassDefFoundError:IllegalName: firstDemo/Test

       java.lang.ClassLoader.preDefineClass(Unknown Source)

       java.lang.ClassLoader.defineClass(Unknown Source)

       java.security.SecureClassLoader.defineClass(Unknown Source)

org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2277)

org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)

org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)

org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)

org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)

org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)

org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)

org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)

org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

       java.util.concurrent.ThreadPoolExecutor.runWorker(UnknownSource)

       java.util.concurrent.ThreadPoolExecutor$Worker.run(UnknownSource)

org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

       java.lang.Thread.run(Unknown Source)

截图:

初入servlet:Allocate exception for servlet


控制台报错:

Exception Processing /test/hello

java.lang.NoClassDefFoundError: IllegalName: firstDemo/Test

   atjava.lang.ClassLoader.preDefineClass(Unknown Source)

   atjava.lang.ClassLoader.defineClass(Unknown Source)

   atjava.security.SecureClassLoader.defineClass(Unknown Source)

   atorg.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2277)

   atorg.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)

   atorg.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)

   atorg.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)

   atorg.apache.catalina.core.StandardWrapper.servletSecurityAnnotationScan(StandardWrapper.java:1128)

   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)

   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)

   atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)

   atorg.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)

   atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

   atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)

   atorg.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)

   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

   atorg.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)

   atorg.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)

   atorg.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

   atjava.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

   atjava.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

   at java.lang.Thread.run(Unknown Source)

截图如下:

初入servlet:Allocate exception for servlet


看了好久,发现是在web.xml中配置错了,复制程序的完整路径直接粘贴过来,去掉开头的src什么的,最后是这样的<servlet-class>firstDemo/Test</servlet-class>

然而这里应该写包名.类名。疏忽大意了

初入servlet:Allocate exception for servlet

重新配置一下后正确。