Tag Archives: web.xml

[Solved] Java EE file upload Error: web.xml error

Javaee file upload
Web.xml error
The error content is as follows:

cvc-id.3: A field of identity constraint ‘web-common-servlet-name-uniqueness’ matched element ‘web-app’, but this element
does not have a simple type.

Solution:

xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee
Change the ‘java’ to uppercase

[Solved] IDEA javaweb web.xml File Error: Invalid content was found starting with element

Error reporting site restore

The header of the web.xml file is declared as follows:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

The servlet elements reporting errors are as follows:

<servlet>
    <description>Enter Dispatcher</description>
    <servlet-name>xxxMVC</servlet-name>
    <servlet-class>com.xxx.web.servlet.RequestDispatcher</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>xxxName</param-name>
        <param-value>xxxValue</param-value>
    </init-param>
</servlet>

Or maybe this

Error prompt in <init-param>the line, given the specific contents are as follows:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. One of '{"http://xmlns.jcp.org/xml/ns/javaee":enabled, 
 "http://xmlns.jcp.org/xml/ns/javaee":async-supported, "http://xmlns.jcp.org/xml/ns/javaee":run-as, "http://xmlns.jcp.org/xml/ns/javaee":security-
 role-ref, "http://xmlns.jcp.org/xml/ns/javaee":multipart-config}' is expected.

Or the following error

Invalid content was found starting with element '{"http://xmlns.jcp.org/xml/ns/javaee":servlet-class}'. 
One of '{"http://xmlns.jcp.org/xml/ns/javaee":description, "http://xmlns.jcp.org/xml/ns/javaee":display-name, 
"http://xmlns.jcp.org/xml/ns/javaee":icon, "http://xmlns.jcp.org/xml/ns/javaee":servlet-name}' is expected.

The solution is as follows:

The init-paramelement to move the entire load-on-startupelement before, after modification, as follows:

<servlet>
    <description>Enter Dispatcher</description>
    <servlet-name>xxxMVC</servlet-name>
    <servlet-class>com.xxx.web.servlet.RequestDispatcher</servlet-class>
    <init-param>
        <param-name>xxxName</param-name>
        <param-value>xxxValue</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Or

Error cause analysis (only for the first error):

Because it is the servletelement of error, so we try to find the corresponding xsd file, look at the error place in violation of which of the restrictions or constraints. According to the statement xml file header, we know that the corresponding xsd files are http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd, but from the web-app_3_1.xsdfile, we define the corresponding constraint did not find. However, we found the following code snippet:

<xsd:include schemaLocation="web-common_3_1.xsd"/>

So, we try to continue to web-common_3_1.xsdfind the corresponding limit or constraint, we find the following two snippets:

<xsd:element name="servlet" type="javaee:servletType"/>
<xsd:complexType name="servletType">
    ......
    <xsd:sequence>
        ......
        <xsd:element name="init-param"
                     type="javaee:param-valueType"
                     minOccurs="0"
                     maxOccurs="unbounded"/>
        <xsd:element name="load-on-startup"
                     type="javaee:load-on-startupType"
                     minOccurs="0">
        </xsd:element>
        ......
    </xsd:sequence>
    ......
</xsd:complexType>

From the above two pieces of code, we know that, for the servletelements, by <xsd:sequence>limiting the order of appearance of the child elements init-parammust appear load-on-startupbefore. At this point, we finally understand that the reason for the error is that we set the wrong order of the child elements.

 

How to Solve Web APP Tag Error in Web.xml

Web app error

The content of element type “web-app” must match……

Cause of problem

Not according to web app_2_3. Write web app tags according to DTD specification

Solution:

1. Write according to the specification, that is, write web app tags according to the order of tags in the error message. (recommended)

2. Delete the specification directly.

Springboot 2.4 package error, missing web.xml

Exception occurred during packaging in springboot 2.4:

  The details are as follows:

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project pts_job: 
Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

The reason is the lack of web.xml. It doesn’t make sense. The springboot project doesn’t need this file. The main reason is that the servlet version in Maven war plugin is too low. It is required to have a web.xml file.

The solution is to upgrade its version. Here, the following version is used:

<build>
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
    </plugin>
</build>

After adding its plug-in, it can be packaged successfully.

 

maven web web.xmlThe markup in the document following the root element must be well-formed.

This is the beginning constraint of web. XML in Maven project

<?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"
    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" />

When you add something after it, you will report an error:

The markup in the document following the root element must be well-formed.

Translation error: the markup in the document after the root element must be well formed

Solution:

<?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"
    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" >
</web-app>