2017-05-10 14 views
0

我目前的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>contextConfigLocation</param-name> 
<param-value>classpath:com/udemy/spring/config/security-context.xml</param-value> 
</context-param> 

<filter> 
<filter-name>springSecurityFilterChain</filter-name> 
<filter- 
class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<listener> 
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<servlet> 
    <servlet-name>dispatcherServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
<load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
<servlet-name>dispatcherServlet</servlet-name> 
<url-pattern>/</url-pattern> 
</servlet-mapping> 
</web-app> 

但例如,如果我重新洗牌的代码顺序例如。这样

<filter> 
<filter-name>springSecurityFilterChain</filter-name> 
<filter- 
class>org.springframework.web.filter.DelegatingFilterProxy</filter- 
class> 
</filter> 

<filter-mapping> 
<filter-name>springSecurityFilterChain</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 

<context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>classpath:com/udemy/spring/config/security-context.xml</param-value> 
</context-param> 

我收到此错误: -

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

能有人给我解释一下可能是什么原因呢?

+0

哪里是在web-app标签在你的第二个例子?并在哪行你得到这些错误? – Jens

回答

0

web.xml元素的顺序是在您在第一行中所指定的DTD文件中定义被用来验证web.xml

http://java.sun.com/dtd/web-app_2_3.dtd

如果打开这个文件,你会看到如下命令:

  1. 图标
  2. 显示名称
  3. 描述
  4. ...等

正如在此元素定义:

<!ELEMENT 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*)>