web.xml内容应该按顺序排列吗?

时间:2017-05-10 13:47:35

标签: java spring web.xml

我当前的web.xml文件如下所示。这并没有显示任何错误。

f = open('test_inputfile.txt').readlines()
f = [i.strip('\n').split(',') for i in f]
for line in f:
    for word in line:
       if word.startswith('spam'):

但是例如,如果我重新调整代码顺序,例如。像这样

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

有人可以解释一下可能是什么原因吗?

2 个答案:

答案 0 :(得分:0)

web.xml文件由dtd或xml架构验证。

在此示例中为http://java.sun.com/dtd/web-app_2_3.dtd

因此web.xml根据此dtd严格定义了标签的顺序

答案 1 :(得分:0)

web.xml元素的顺序在您在第一行中指定的DTD文件中定义,用于验证web.xml

  

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

如果您打开此文件,您将看到如下命令:

  1. 图标
  2. 显示名称
  3. 描述
  4. ...... etc
  5. 正如在这个元素中定义的那样:

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