2012-09-18 109 views
24

我的web.xml文件有问题。错误:元素类型“...”的内容必须在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.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。有关这个问题的任何想法?

+0

是的,这个文件的顺序把我定期的拧紧了。根据你发布的DTD片段,welcome-file-list应该出现在servlet和servlet映射之后。试试看。 – Faelkle

+0

不,这不是问题。标签的顺序完全适合DTD。 – erencan

+2

好吗? [the DTD](http://svn.apache.org/repos/asf/beehive/trunk/netui/external/struts/web-app_2_3.dtd)指出'welcome-file-list'在'servlet-映射“ - 它后来在逗号分隔的元素列表中。 – Faelkle

回答

11

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

+2

你是什么意思'重新命令标签为DTD'? – CodyBugstein

+5

重新排序标签意味着以web.xml指定的方式排列标签(如图标,显示名称,servlet,servlet映射)。您可以在eclipse中的鼠标悬停时看到帮助消息中的顺序。 – Rajkumar

+0

@Rajkumar这确实解决了这个问题。 –

0

重新安排这样的代码......

<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映射。

3

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

+1

我做了同样的...得到它解决..谢谢:) – ppuskar

0

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

46

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

更改从

<!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 conent goes here 

</web-app> 
+0

这真的为我工作。谢谢 –

+0

将'<!DOCTYPE ...'行改为'<?xml ...'对我来说已经足够了。 –

7

我观察到,在DTD的Web.xml所需元件的servlet,Servlet映射的特定顺序的模式参考等

因此,我开始在ECLIPSE中添加XML文件设计视图中的每个元素。

它的工作原理!您可以用它喜欢的DTD来构建XML文件。

+0

很好的答案,谢谢。 – Kenci

2

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

相关问题