sagar limbu
sagar limbu

Reputation: 1262

should web.xml contents should be in order?

my current web.xml file looks like this. and this is does not show any error.

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

but for example if i reshuffle the code order for eg. like this

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

i am getting this error:-

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*)".

can someone explain me what might be the reason?

Upvotes: 0

Views: 800

Answers (2)

fujy
fujy

Reputation: 5264

The order of web.xml elements is defined in the DTD file that you have specified in the first line to be used to validate the web.xml

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

If you open this file, you will see the order as follows:

  1. icon
  2. display-name
  3. description
  4. ... etc

As it is defined in this element:

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

Upvotes: 1

Mike Adamenko
Mike Adamenko

Reputation: 3002

web.xml file validates by dtd or xml schema.

In this example by http://java.sun.com/dtd/web-app_2_3.dtd

So web.xml has strictly defined order of tags according to this dtd

Upvotes: 0

Related Questions