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

ere*_*can 35 eclipse web.xml

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

元素类型"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进入*,EJB-REF*,EJB本地-REF*)".

但是,我的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>
Run Code Online (Sandbox Code Playgroud)

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

Usm*_*hir 66

一个非常简单的解决方案,解决了我的问题.

更改架构引用

<!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>
Run Code Online (Sandbox Code Playgroud)

对此

<?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>
Run Code Online (Sandbox Code Playgroud)


Coo*_*.Wu 16

我在Eclipse中遇到了同样的问题,在重新命令标签作为DTD之后,错误就开始了.您也可以尝试重新启动Eclipse.

  • 重新排序标记意味着按照web.xml指定的方式排列标记(如图标,显示名称,servlet,servlet映射).您可以在eclipse中将鼠标悬停在错误上时看到帮助消息中的顺序. (6认同)
  • 你是什​​么意思"重新订购标签为DTD"? (2认同)

Aqu*_*les 7

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

所以,我开始在ECLIPSE中添加XML文件的Design View中的每个元素.

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


小智 5

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