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

时间:2012-09-18 07:46:54

标签: eclipse web.xml

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

  

元素类型“web-app”的内容必须匹配   “(图标?,显示名称?,描述?,分发?,的context-param *,滤波器*,过滤器 -   映射*,听者*,* servlet的,servlet的映射*,会话配置?,MIME映射*,欢迎文件列表?,错误页*,*的taglib,资源env-   REF *,资源引用*,安全约束*,登录-配置?,安全角色*,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>

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

9 个答案:

答案 0 :(得分:62)

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

更改架构参考
<!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>

到这个

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

答案 1 :(得分:14)

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

答案 2 :(得分:7)

我发现Web.xml中的DTD需要元素servlet,servlet-mapping等的特定顺序。

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

它有效!您可以以喜欢DTD的方式构建XML文件。

答案 3 :(得分:4)

我遵循了某人的建议&#34;复制所有&#34; - &#34; cut&#34; - &#34;粘贴&#34; - &#34;保存&#34;这似乎清除了这个信息。比较之前和之后的文件,我发现在&#34;粘贴&#34;版本所有选项卡都已转换为空格。所以似乎Eclipse中的web.xml验证器不喜欢标签。

答案 4 :(得分:4)

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

答案 5 :(得分:1)

重新安排你的代码......

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

如果你有更多的servlet然后在映射之上定义你的servlet,那么在那之后映射你的servlet。

答案 6 :(得分:1)

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

答案 7 :(得分:1)

最后,我通过在eclipse中使用设计视图配置servlet和servlet-mapping而不是直接在源视图中的web.xml中键入来解决此问题。希望这会有所帮助。

答案 8 :(得分:1)

此部分已删除,错误已解决。

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