【问题标题】:Java servlet web.xml file cannot resolve the class in the <servlet-class> tag in IntelliJJava servlet web.xml 文件无法解析 IntelliJ 中 <servlet-class> 标记中的类
【发布时间】:2022-01-30 05:15:39
【问题描述】:

我正在编写一个简单的 Web 服务,并将我的 web.xml 文件放在 WEB-INF 文件夹中。出于某种原因,servlet-class 标记中的所有内容都显示为 “无法解析 MyServlet 类”。 MyServlet 类位于根目录下的 src 文件夹中。我不知道为什么会发生这种情况。

 <web-app
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1">

<servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>MyServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/my/*</url-pattern>
</servlet-mapping>

【问题讨论】:

    标签: java xml intellij-idea servlets web.xml


    【解决方案1】:

    我需要在 IntelliJ 中将我的 src 文件夹标记为“Source Root”。这可以通过右键单击文件夹 -> 将目录标记为来完成。在那之后,我的类文件实际上变成了可链接的。

    【讨论】:

      猜你喜欢
      • 2015-11-16
      • 2015-09-07
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      • 2014-11-10
      • 1970-01-01
      • 2020-01-06
      • 1970-01-01
      相关资源
      最近更新 更多