12

I am using Eclipse Helios Release. Eclipse xml validator doesn't like the display-name element under <servlet> in my web.xml. Here's the relevant part:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee" 
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  id="WebApp_ID"
  version="2.5">

  <display-name>PropTax</display-name>
  <servlet> 
    <servlet-name>PropTax</servlet-name>     
    <display-name>PropTax</display-name> 
    <servlet-class>org.slco.treasurer.propertytax.servlet.PropTax</servlet-class>
  </servlet>
  (...)

If I remove display-name element then there is no error anymore. If I understand correctly 2.5 is the right schema to support display-name, and even context help under the editor will list display-name as part of choice.

Could anyone help me here?

Error message from Eclipse validator:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'display-name'. One of '{"http://java.sun.com/xml/ns/javaee":servlet-class, "http://java.sun.com/xml/ns/javaee":jsp-file}' is expected. web.xml /PropTax/WebContent/WEB-INF line 6 XML Problem
zb226
  • 9,586
  • 6
  • 49
  • 79
juny fan
  • 121
  • 1
  • 1
  • 3

5 Answers5

16

You need to use the '101010' button to quote your XML for it to be readable.

However, according to the XSD you referenced, a servlet definition (servlet tag) needs to have the description stuff (including display-name) before the servlet-name. Given the error you've posted, I suspect you've got servlet-name followed by display-name. However, it's hard to tell without seeing the XML well formatted.

dty
  • 18,795
  • 6
  • 56
  • 82
9

Move "display-name" as the first element under "servlet" tag, the validation error should go away.

<servlet> 
 <display-name>PropTax</display-name> 
 <servlet-name>PropTax</servlet-name>     
 <servlet-class>org.slco.treasurer.propertytax.servlet.PropTax</servlet-class>
</servlet>
user959740
  • 111
  • 1
  • 3
6

change xmlns = "http://java.sun.com/xml/ns/j2ee" to xmlns="http://xmlns.jcp.org/xml/ns/javaee" and the error should go. It worked for me. or else follow convention according ot java.sun.com and add move display-name under the servlet tag.

1

Comment out the warning/error (or all) elements from servlet tab, and use eclipse web.xml Design editor to "Add Child" for "display-name". Eclipse WEB.XML design editor will automatically update the XML file with validator arranged order.

ckl
  • 71
  • 1
  • 1
  • 4
0

You have to put the tag display-name first.

<servlet>
<display-name>PropTax</display-name>
<servlet-name>PropTax</servlet-name>      
<servlet-class>org.slco.treasurer.propertytax.servlet.PropTax</servlet-class>

Avnish
  • 44
  • 7