问题描述:
(错误信息找 Caused by)
Caused by: java.lang.IllegalArgumentException: servlet映射中的<url pattern>[FindAllStudentServlet]无效 at org.apache.catalina.core.StandardContext.addServletMappingDecoded(StandardContext.java:3173) at org.apache.catalina.core.StandardContext.addServletMappingDecoded(StandardContext.java:3160) at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1389) at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1166) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:779) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5053) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ... 44 more
原错误代码
(Servlet里注解的资源访问路径没有以 / 开头)
Servlet.java
// 注解 替代.xml的映射 @WebServlet("FindAllStudentServlet")
解决方法:注解的资源访问路径必须是/开头
修改后代码
// 注解 替代.xml的映射 @WebServlet("/FindAllStudentServlet")
运行结果
控制台显示结果
页面显示结果