关于web.xml报错问题解决

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于web.xml报错问题解决相关的知识,希望对你有一定的参考价值。

参考技术A 一、现象

配置web.xml时,出现红色叉叉,提示The content of element type "web-app" must match "(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*)".- No grammar constraints (DTD or XML schema) detected for the document.

二、原因

这是由于web-app标签里面的子标签顺序不对,只需按照提示的顺序修改标签顺序就可以了,或者修改web.xml的schema

三、解决办法

1:严格按照提示上的顺序排列

2:删除<!DOCTYPE 。。。。这段内容,即<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN "http://java.sun.com/dtd/web-app_2_3.dtd">删除这行

3.修改web.xml的schema

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

<web-app xmlns="http://java.sun.com/xml/ns/javaee"

        version="3.0"

        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_3.0.xsd">

        // your all conent goes here

</web-app>

关于web.xml3.0启动报错

技术分享
九月 08, 2017 10:18:19 上午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source‘ to ‘org.eclipse.jst.jee.server:war_item‘ did not find a matching property.
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version:        Apache Tomcat/7.0.69
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built:          Apr 11 2016 07:57:09 UTC
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number:         7.0.69.0
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name:               Windows 8
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version:            6.2
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture:          amd64
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home:             H:\work\jre
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version:           1.7.0_45-b18
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor:            Oracle Corporation
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE:         H:\CJD\cjd\apache-tomcat-7.0.69_8080
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME:         H:\CJD\cjd\apache-tomcat-7.0.69_8080
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:53038
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=H:\CJD\cjd\apache-tomcat-7.0.69_8080
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=H:\CJD\cjd\apache-tomcat-7.0.69_8080
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dwtp.deploy=H:\CJD\cjd\apache-tomcat-7.0.69_8080\wtpwebapps
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=H:\CJD\cjd\apache-tomcat-7.0.69_8080\endorsed
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dfile.encoding=GBK
九月 08, 2017 10:18:20 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: H:\work\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;H:\work\jre\bin;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;D:\oracle\product\10.2.0\db_1\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;H:\work\bin;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\IntelSGXPSW\bin\x64\Release\;C:\Program Files\Intel\IntelSGXPSW\bin\win32\Release\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\mySQL\bin;D:\MySQL\MySQL Server 5.5\bin;C:\Program Files\VisualSVN Server\bin;D:\SVN\bin;G:\apache-maven-3.3.9\bin;G:\apache-cxf-3.0.9\bin;C:\Users\zxz\AppData\Local\Microsoft\WindowsApps;;.
九月 08, 2017 10:18:20 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-9090"]
九月 08, 2017 10:18:20 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-9972"]
九月 08, 2017 10:18:20 上午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1216 ms
九月 08, 2017 10:18:20 上午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
九月 08, 2017 10:18:20 上午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.69
九月 08, 2017 10:18:21 上午 org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
信息: validateJarFile(H:\CJD\cjd\apache-tomcat-7.0.69_8080\wtpwebapps\war_item\WEB-INF\lib\el-api-6.0.29.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
九月 08, 2017 10:18:21 上午 org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
信息: validateJarFile(H:\CJD\cjd\apache-tomcat-7.0.69_8080\wtpwebapps\war_item\WEB-INF\lib\servlet-api-6.0.29.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
九月 08, 2017 10:18:23 上午 org.apache.catalina.core.ContainerBase startInternal
严重: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/war_item]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1120)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/war_item]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2397)
    at java.lang.Class.getDeclaredFields(Class.java:1806)
    at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
    at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:270)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:139)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:416)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:890)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:387)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5472)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: org.springframework.web.context.WebApplicationContext
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
    ... 20 more

九月 08, 2017 10:18:23 上午 org.apache.catalina.core.ContainerBase startInternal
严重: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1120)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:444)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:756)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:693)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 6 more

九月 08, 2017 10:18:23 上午 org.apache.catalina.startup.Catalina start
严重: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[9071]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:693)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:756)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:444)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 11 more

九月 08, 2017 10:18:23 上午 org.apache.coyote.AbstractProtocol pause
信息: Pausing ProtocolHandler ["http-bio-9090"]
九月 08, 2017 10:18:23 上午 org.apache.coyote.AbstractProtocol pause
信息: Pausing ProtocolHandler ["ajp-bio-9972"]
九月 08, 2017 10:18:23 上午 org.apache.catalina.core.StandardService stopInternal
信息: Stopping service Catalina
九月 08, 2017 10:18:23 上午 org.apache.coyote.AbstractProtocol destroy
信息: Destroying ProtocolHandler ["http-bio-9090"]
九月 08, 2017 10:18:23 上午 org.apache.coyote.AbstractProtocol destroy
信息: Destroying ProtocolHandler ["ajp-bio-9972"]
View Code

以上是web.xml3.0启动报错信息,解决办法:就是将web.xml配置文件中的版本号改为2.5版本的即可

常用的web.xml版本头文件:

web.xml3.0

<?xml version=”1.0″ encoding=”utf-8″?>
<web-app version=”3.0″
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_3_0.xsd”>

web.xml2.5

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

web.xml2.4

<?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/j2ee”
xmlns:web=”http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ”
version=”2.4″>

 

以上是关于关于web.xml报错问题解决的主要内容,如果未能解决你的问题,请参考以下文章

eclipse:web.xml<el-ignored>标签报错解决方法

web.xml报错

idea中,使用facets添加完web后,项目已变为web项目,但web.xml中内容经常变为红色,并报错,如何解决?

web.xml配置文件中true报错的解决方案

关于报错“More than one fragment with the name [spring_web] was found. This is not legal ...”的解决办法

关于报错“More than one fragment with the name [spring_web] was found. This is not legal ...”的解决办法