What does this web.xml error mean?

2019-03-12 08:51发布

问题:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">

Referenced file contains errors (http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd). For more information, right click on the message in the Problems View and select "Show Details..."

The errors below were detected when validating the file "web-app_2_5.xsd" via the file "web.xml". In most cases these errors can be detected by validating "web-app_2_5.xsd" directly. However it is possible that errors will only occur when web-app_2_5.xsd is validated in the context of web.xml.

In details, I see a bunch of these:

s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than xs:appinfo and xs:documentation. Saw 'var _U="undefined";'

回答1:

If you replace j2ee by javaee, it will work fine.

EDIT :

<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    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">

Edit:

To know anything further related to this error. Please follow the Link. Here you will find schemas for Java EE deployment descriptors (web.xml).



回答2:

replace

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">

with

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee;http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">

The solution is that you have to put semicolon between URLs

I am sure you will not get the error again :)



回答3:

On the surface it appears that the schemaLocation is wrong. Resolving it appears to redirect to a HTML page rather than a XSD schema.

I would suggest simply removing this line unless you really want to do XSD validation at runtime. Bear in mind the relevant parts will be validated by your servlet container.



回答4:

In my case, I had replaced

xsi:schemaLocation="http://java.sun.com/../.."

with

xsi:schemaLocation="http://xmlns.jcp.org/../.."

Cheers!



回答5:

I suggest you add ; between 2 passages: xsi:schemaLocation="http://java.sun.com/xml/ns/javaee and http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

Like this:

:xsi:schemaLocation="http://java.sun.com/xml/ns/javaee;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">