使用STRICT_SERVLET_COMPLIANCE = true

时间:2017-02-14 05:18:08

标签: java apache tomcat tomcat8

我正在尝试通过更新apache-tomcat-8.0.39 \ conf \ catalina.properties在Tomcat 8.0.39上部署一个带有选项STRICT_SERVLET_COMPLIANCE = true的应用程序,但是一旦我这样做,我的应用程序部署就失败了。 即我开始收到错误: SEVERE [localhost-startStop-1] org.apache.tomcat.util.digester.Digester.error应用程序web.xml文件中所有标记的解析错误。

其中一个堆栈跟踪如下:

  

09-Feb-2017 15:06:32.189 SEVERE [localhost-startStop-1] org.apache.tomcat.util.digester.Digester.error第5行第66行的分析错误:文档根元素" web -app",必须匹配DOCTYPE root" xml"。    org.xml.sax.SAXParseException; systemId:file:/ C:/Servers/Tomcat%208/apache-tomcat-8.0.39/webapps/file-service/WEB-INF/web.xml; lineNumber:5; columnNumber:66;文档根元素" web-app",必须与DOCTYPE root" xml"匹配。       at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)       at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl $ NSContentDriver.scanRootElementHook(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl $ FragmentContentDriver.next(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl $ PrologDriver.next(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)       at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)       在com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(未知来源)       at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)       at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl $ JAXPSAXParser.parse(Unknown Source)       在org.apache.tomcat.util.digester.Digester.parse(Digester.java:1448)       在org.apache.tomcat.util.descriptor.web.WebXmlParser.parseWebXml(WebXmlParser.java:119)       在org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1119)       在org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:783)       at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:307)       在org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)       在org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)       在org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5213)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)       在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1408)       在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1398)       at java.util.concurrent.FutureTask.run(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)       在java.lang.Thread.run(未知来源)

为解决该问题,我尝试了以下选项:

1)在catalina.properties中添加了以下内容:

org.apache.catalina.STRICT_SERVLET_COMPLIANCE=true
org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR=false

2)更新了代理WAR web.xml文件 使用web-app_2_5.xsd更新了web-app_3_0.xsd 更新版本=" 3.0"版本=" 2.5"

我也尝试过复制" web-app"标记条目从apache-tomcat-8.0.39 \ conf \ web.xml到我的应用程序web.xml但没有用。

3)尝试将以下值设置为各自的默认值[作为设置

org.apache.catalina.STRICT_SERVLET_COMPLIANCE=true changes these defaults]
org.apache.catalina.core.ApplicationContext.GET_RESOURCE_REQUIRE_SLASH
org.apache.catalina.core.ApplicationDispatcher.WRAP_SAME_OBJECT
org.apache.catalina.core.StandardHostValve.ACCESS_SESSION
org.apache.catalina.session.StandardSession.ACTIVITY_CHECK
org.apache.catalina.session.StandardSession.LAST_ACCESS_AT_START
org.apache.tomcat.util.http.ServerCookie.STRICT_NAMING

The **URIEncoding** attribute of any HTTP connector or AJP connector element.
The **resourceOnlyServlets** attribute of any Context element.
The **tldValidation** attribute of any Context element.
The **useRelativeRedirects** attribute of any Context element.
The **xmlNamespaceAware** attribute of any Context element.
The **xmlValidation** attribute of any Context element.

但似乎没有什么工作正常。我也无法导航到tomcat管理器或部署的任何其他应用程序。

另一方面,当我在catalina.properties中写STRICT_SERVLET_COMPLIANCE = false时,一切正常。

这里有什么我想念的吗?请帮我解决这个问题。

此致 布佩希

1 个答案:

答案 0 :(得分:1)

我也遇到了这个问题。我们工作的环境要求将STRICT_SERVLET_COMPLIANCE设置为true,但web.xml的验证不是该要求背后的驱动力。要解决此问题,请尝试在conf / context.xml标记中将xmlValidation设置为false:

<Context xmlValidation="false"> ... </Context>