Tag Archives: JavaWeb

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

 

The requested resource [/servlet] in JavaWeb is not available [How to Solve]

Problem Description: after submitting the form, an error is reported, and the servlet is unavailable

Solution:

The development tool I use is idea2020. First, check whether comments are added:

2. Through consulting materials, it is said that servlets should be configured under web.xml. Here, I run JSP to get the web page source code, but I don’t know why. I haven’t configured web.xml in previous projects

3. Solution: add the following in the web app of web.xml:

<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_4_0.xsd"
         version="4.0">

So far, the problem has been solved.

JavaWeb Error:java.lang.NumberFormatException: null

Error reporting environment:

JSP passes the value to the severlet page. When the serverlet page executes the following statements, the background log reports an error

   int softType = Integer.parseInt(request.getParameter("softType"));
2014-3-27 14:36:57 org.apache.catalina.core.StandardWrapperValve invoke
Warning: Servlet.service() for servlet [softClServlet] in context with path [/dms] threw exception
java.lang.NumberFormatException: null
    at java.lang.Integer.parseInt(Integer.java:417)
    at java.lang.Integer.parseInt(Integer.java:499)
    at com.trs.dms.controller.softClServlet.doPost(softClServlet.java:83)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)

Error log

 

Problem analysis:

This statement converts a null value into int type, that is, the request.getparameter (“softtype”) value is null. Judge whether it is null before conversion. If it is null, skip conversion to a message