Java 严重:应用程序 web.xml 中的解析错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20821513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:35:51  来源:igfitidea点击:

Severe: Parse error in application web.xml

javatomcatweb.xmlsaxparseexception

提问by Dru Freeman

I am trying to teach myself Java, Java EE, and Tomcat pretty much all at once.
(Experienced C/Obj-C dev)

我正在尝试同时自学 Java、Java EE 和 Tomcat。
(有经验的 C/Obj-C 开发者)

I was following a tutorial at YouTube at: http://www.youtube.com/watch?v=bd50C6XUnFw

我正在关注 YouTube 上的教程:http: //www.youtube.com/watch?v=bd50C6XUnFw

I am running:

我在跑步:

  • Apache Tomcat/7.0.47
  • JVM 1.7.0_45-b18
  • Mac OS X 10.8.5 x86_64
  • Apache Tomcat/7.0.47
  • JVM 1.7.0_45-b18
  • Mac OS X 10.8.5 x86_64

The error I'm seeing is:

我看到的错误是:

SEVERE: Parse error in application web.xml file at jndi:/localhost/FirstServlet/WEB-INF/web.xml
org.xml.sax.SAXParseException; systemId: jndi:/localhost/FirstServlet/WEB-INF/web.xml; lineNumber: 8; columnNumber: 19; Error at (8, 19) : Can't convert argument: null
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2719)
    at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1054)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)

As shown in the video the web.xml (at path /Library/Tomcat/webapps/firstservlet/WEB-INF) is:

如视频所示,web.xml(在路径/Library/Tomcat/webapps/firstservlet/WEB-INF)是:

<web-app>
    <servlet>
        <servlet-name>My FirstServlet</servlet-name>
        <servlet-class>FirstServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <url-pattern>/myfirstservlet</url-pattern>
    </servlet-mapping>
</web-app>

The error indicates that the issue is a null it's hitting after the </servlet-mapping>

该错误表明问题是一个空值,它在 </servlet-mapping>

So my only assumption is that the tutorial on YouTube is missing something and I must be missing an argument. Suggestions strongly welcomed.

所以我唯一的假设是 YouTube 上的教程缺少一些东西,我必须缺少一个论点。强烈欢迎提出建议。

采纳答案by PM 77-1

I believe you're missing <servlet-name>...</servlet-name>in <servlet-mapping>section:

我相信你缺少<servlet-name>...</servlet-name><servlet-mapping>部分:

<servlet-mapping>
    <servlet-name>My FirstServlet</servlet-name>
    <url-pattern>/myfirstservlet</url-pattern>
</servlet-mapping>

Have a look at basic web.xml file

看看基本的 web.xml 文件

回答by Diversity

Between the element servlet-mapping the element servlet-name is missing

在元素 servlet-mapping 之间缺少元素 servlet-name

<servlet-mapping>
     <servlet-name>MyFirstServlet</servlet-name>
     <url-pattern>/myfirstservlet</url-patter>
</servlet-mapping>

The servlet name is a kind of id which creates a relationship between url and the guven Servlet class.

servlet 名称是一种 id,它在 url 和 guven Servlet 类之间创建关系。

回答by Stephen C

Suggestions strongly welcomed.

强烈欢迎提出建议。

  1. Don't rely on a single tutorial as your sole source of information ...

  2. These things are specified. If you have doubts about the accuracy of a "secondary source" such as a dubious tutorial video, look at the specification.

  3. If reading a specification is too difficult for you1, then look for a reliable tutorial; e.g. for Java-related stuff, look for one written by Oracle.

  1. 不要依赖单个教程作为您唯一的信息来源......

  2. 这些东西是指定的。如果您对“次要来源”(例如可疑的教程视频)的准确性有疑问,请查看规范。

  3. 如果阅读规范对您来说太难1,那么请寻找可靠的教程;例如,对于与 Java 相关的内容,请查找 Oracle 编写的内容。



1 - People who label a specification "obtuse" are probably missing the real point of the specification. A good specification is written with accuracy, precision and completeness as its primary goals. A (so-called) specification that reads like a tutorial is most likely not meeting its primary goals properly.

1 - 给规范贴上“迟钝”标签的人可能忽略了规范的真正要点。一个好的规范是以准确性、精确性和完整性为主要目标的。读起来像教程的(所谓的)规范很可能没有正确实现其主要目标。



In this case, the Servlet spec 3.0(section 14.4.11) makes it clear that you need a servlet-nameelement to say what Servlet the matching requests are mapped to.

在这种情况下,Servlet 规范 3.0(第 14.4.11 节)明确指出您需要一个servlet-name元素来说明匹配请求映射到哪个 Servlet。

(You could most likely find the same information in other tutorials, etcetera ...)

(您很可能会在其他教程等中找到相同的信息......)