Servlet 应该有映射,不能解析 Servlet
Servlet should have a mapping and cannot resolve Servlet
当我打开我的项目时,出现错误:
Servlet should have a mapping
和另一个错误:
Cannot resolve Servlet
但在下面的代码中,您可以看到每个 servlet 都有其映射:
在我的web.xml
中,我有8个servlet,每个servlet都有对应的映射:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>loginservlet</servlet-name>
<servlet-class>com.sam.servlet.loginservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>changeservlet</servlet-name>
<servlet-class>com.sam.servlet.changeservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Searchservlet</servlet-name>
<servlet-class>com.sam.servlet.Searchservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>borrowservlet</servlet-name>
<servlet-class>com.sam.servlet.borrowservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>mealselectservlet</servlet-name>
<servlet-class>com.sam.servlet.mealselectservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>mealaddservlet</servlet-name>
<servlet-class>com.sam.servlet.mealaddservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>mealdeletedservlet</servlet-name>
<servlet-class>com.sam.servlet.mealdeletedservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>mealupdateservlet</servlet-name>
<servlet-class>com.sam.servlet.mealupdateservlet</servlet-class>
</servlet>
<!-- mapping -->
<servlet-mapping>
<servlet-name>loginservlet</servlet-name>
<url-pattern>/loginservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>changeservlet</servlet-name>
<url-pattern>/changeservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Searchservlet</servlet-name>
<url-pattern>/Searchservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>borrowservlet</servlet-name>
<url-pattern>/borrowservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mealselectservlet</servlet-name>
<url-pattern>/mealselectservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mealaddservlet</servlet-name>
<url-pattern>/mealaddservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mealdeletedservlet</servlet-name>
<url-pattern>/mealdeletedservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mealupdateservlet</servlet-name>
<url-pattern>/mealupdateservlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是一个已知问题,已在当前 IntelliJ IDEA 版本中修复。对于旧版本 there is a workaround:
please open Project Structure | Modules | Web Facet and add your web.xml
as Deployment Descriptor.
作为解决方法,请打开项目结构 -> 模块 -> Web Facet 并添加你的 web.xml
作为部署描述符。
see image detail here
当我打开我的项目时,出现错误:
Servlet should have a mapping
和另一个错误:
Cannot resolve Servlet
但在下面的代码中,您可以看到每个 servlet 都有其映射:
在我的web.xml
中,我有8个servlet,每个servlet都有对应的映射:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>loginservlet</servlet-name>
<servlet-class>com.sam.servlet.loginservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>changeservlet</servlet-name>
<servlet-class>com.sam.servlet.changeservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Searchservlet</servlet-name>
<servlet-class>com.sam.servlet.Searchservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>borrowservlet</servlet-name>
<servlet-class>com.sam.servlet.borrowservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>mealselectservlet</servlet-name>
<servlet-class>com.sam.servlet.mealselectservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>mealaddservlet</servlet-name>
<servlet-class>com.sam.servlet.mealaddservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>mealdeletedservlet</servlet-name>
<servlet-class>com.sam.servlet.mealdeletedservlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>mealupdateservlet</servlet-name>
<servlet-class>com.sam.servlet.mealupdateservlet</servlet-class>
</servlet>
<!-- mapping -->
<servlet-mapping>
<servlet-name>loginservlet</servlet-name>
<url-pattern>/loginservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>changeservlet</servlet-name>
<url-pattern>/changeservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Searchservlet</servlet-name>
<url-pattern>/Searchservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>borrowservlet</servlet-name>
<url-pattern>/borrowservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mealselectservlet</servlet-name>
<url-pattern>/mealselectservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mealaddservlet</servlet-name>
<url-pattern>/mealaddservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mealdeletedservlet</servlet-name>
<url-pattern>/mealdeletedservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mealupdateservlet</servlet-name>
<url-pattern>/mealupdateservlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是一个已知问题,已在当前 IntelliJ IDEA 版本中修复。对于旧版本 there is a workaround:
please open Project Structure | Modules | Web Facet and add your
web.xml
as Deployment Descriptor.
作为解决方法,请打开项目结构 -> 模块 -> Web Facet 并添加你的 web.xml
作为部署描述符。
see image detail here