简体   繁体   English

Java servlet web.xml 文件无法解析 ZA2F2ED4F8EBC04661C21A2DC9<servlet-class> IntelliJ 中的标记</servlet-class>

[英]Java servlet web.xml file cannot resolve the class in the <servlet-class> tag in IntelliJ

I am writing a simple web service and have put my web.xml file in the WEB-INF folder.我正在编写一个简单的 web 服务并将我的 web.xml 文件放在 WEB-INF 文件夹中。 For some reason everything in the servlet-class tag is coming up as "cannot resolve class MyServlet" .由于某种原因, servlet-class标记中的所有内容都显示为“无法解析 class MyServlet” The class MyServlet is in the src folder under root directory. class MyServlet 位于根目录下的 src 文件夹中。 I cannot figure out why as to why this is happening.我无法弄清楚为什么会发生这种情况。

 <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>

Sorry for the dumb question I figured it out...... It turns out I needed to mark my src folder as "Source Root" in IntelliJ, this can be done by right clicking the folder -> mark directory as.抱歉,我想出了这个愚蠢的问题......原来我需要在 IntelliJ 中将我的 src 文件夹标记为“Source Root”,这可以通过右键单击文件夹 -> 将目录标记为来完成。 After that my class files actually became linkable.在那之后,我的 class 文件实际上变成了可链接的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM