eclipse 元素类型“...”的内容必须在 web.xml 中匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12472541/
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-09-10 21:19:33  来源:igfitidea点击:

The content of element type "..." must match in web.xml

eclipseweb.xml

提问by erencan

I have a problem with my web.xml file. The error:

我的 web.xml 文件有问题。错误:

The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter- mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env- ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)".

元素类型“web-app”的内容必须匹配“(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping *,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security -role*,env-entry*,ejb-ref*,ejb-local-ref*)”。

However, my web.xml file is in the order what error say.

但是,我的 web.xml 文件的顺序是错误所说的。

Here is my web.xml:

这是我的 web.xml:

<!DOCTYPE web-app PUBLIC
         "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
         "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    </context-param>
    ??
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
        <description></description>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    ??
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

</web-app>

I use WebLogic 10.3.4. Any idea about the problem?

我使用 WebLogic 10.3.4。对这个问题有什么想法吗?

回答by Usman Tahir

One very simple solution which solves my problem.

一个非常简单的解决方案可以解决我的问题。

Change the schema reference from

将架构引用从

<!DOCTYPE web-app PUBLIC
   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app></web-app>

to this

对此

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
         version="2.5" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
         // ...
         // your all content goes here

</web-app>

回答by Cooper.Wu

I had the same problem in Eclipse, after re-order tags as DTD, the error goes way. You may also try to restart Eclipse.

我在 Eclipse 中遇到了同样的问题,在将标签重新排序为 DTD 后,错误消失了。您也可以尝试重新启动 Eclipse。

回答by Aquiles

I observed that DTD at Web.xml required an specific order for elements servlet, servlet-mapping, etc.

我观察到 Web.xml 中的 DTD 需要元素 servlet、servlet-mapping 等的特定顺序。

So, I started adding each element from Design View of XML file at ECLIPSE.

所以,我开始从 ECLIPSE 的 XML 文件的设计视图中添加每个元素。

It works!. You can build your XML file in a way it likes to DTD.

有用!。您可以按照 DTD 喜欢的方式构建 XML 文件。

回答by fozersahin

I just removed <!DOCTYPE .. >tag and it worked for me. Actually I don't know how much important..

我刚刚删除了<!DOCTYPE .. >标签,它对我有用。其实我不知道有多重要..

回答by Bill H

I followed someone's suggestion for "copy all" - "cut" - "paste" - "save" and this seemed to clear up the message. Comparing the before and after files, I found that in the "pasted" version all tabs had been converted to spaces. So it seems that the web.xml validator in Eclipse does not like tabs.

我按照某人的建议“全部复制”-“剪切”-“粘贴”-“保存”,这似乎清除了信息。比较前后文件,我发现在“粘贴”版本中,所有制表符都已转换为空格。所以看起来 Eclipse 中的 web.xml 验证器不喜欢选项卡。

回答by Chamila Maddumage

This part was removed and errors were solved.

这部分被删除并解决了错误。

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"  "http://java.sun.com/dtd/web-app_2_3.dtd" >

回答by Pierre C

Just don't forget to save the file when trying the above solutions. The error went away in my case after using the latest schema descriptorand saving :

尝试上述解决方案时,请不要忘记保存文件。在使用最新的模式描述符并保存后,错误在我的情况下消失了:

<?xml version="1.0" encoding="UTF-8"?>
<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"
    id="WebApp_ID" version="3.1">

    <!-- your content here -->

</web-app>`

回答by techy2k

If you are dealing with this same issue and find nothing at all wrong with web.xml syntax, I recommend doing the following: "cut (all content within web.xml)", "paste to notepad" - "copy from notepad" - "paste back into web.xml" - "and finally save web.xml". Got to love those invisible characters, tabs, etc.

如果您正在处理同样的问题并且发现 web.xml 语法没有任何问题,我建议您执行以下操作:“剪切(web.xml 中的所有内容)”、“粘贴到记事本”-“从记事本复制”- “粘贴回 web.xml” - “最后保存 web.xml”。必须喜欢那些隐形字符、标签等。

回答by Muhammad Suleman

rearrange your code like this...

像这样重新排列你的代码......

<web-app>
  <display-name>Archetype Created Web Application</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

 <context-param>   
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
  </context-param>

  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
    <description></description>>
  </context-param>

  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
 <servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>

and if you have more servlet then define your servlet above the mapping then map your servlet after that.

如果您有更多的 servlet,则在映射上方定义您的 servlet,然后再映射您的 servlet。

回答by Freelancer

Finally i resolved this issue by configuring servlet and servlet-mapping by using design view in eclipse instead of typing directly in the web.xml in source view. Hope this helps.

最后,我通过在 eclipse 中使用设计视图而不是直接在源视图中的 web.xml 中键入来配置 servlet 和 servlet 映射,从而解决了这个问题。希望这可以帮助。