eclipse 为什么 web.xml 'context-param' 不能有字符 [children]?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15388084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:10:37  来源:igfitidea点击:

Why web.xml 'context-param' cannot have character [children]?

eclipsejakarta-ee

提问by huahsin68

I am just curious what happen to this web.xmlcode where I have this error cvc-complex-type.2.3: Element 'context-param' cannot have character [children], because the type's content type is element-only.in the Eclipse (juno version) Markersview.

我只是好奇这段web.xml代码会发生什么,我cvc-complex-type.2.3: Element 'context-param' cannot have character [children], because the type's content type is element-only.在 Eclipse(juno 版本)Markers视图中出现此错误。

Here is the code:

这是代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 
        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">

  <display-name>Spring security web application (series)</display-name>

?  <!-- to specifically stop trouble with multiple apps on tomcat -->
?  <context-param>
?  ?  <param-name>webAppRootKey</param-name>
?  ?  <param-value>customauth_root</param-value>
?  </context-param>

?  <!-- Location of the XML file that defines the root application context
?  ?  applied by ContextLoaderListener. -->
?  <context-param>
?  ?  <param-name>contextConfigLocation</param-name>
?  ?  <param-value>
?      ?  WEB-INF/applicationContext.xml
?      ?  WEB-INF/applicationContext-security.xml
        </param-value>
?  </context-param>

?  <!-- Loads the root application context of this web app at startup. The
?  ?  application context is then available via WebApplicationContextUtils.getWebApplicationContext(servletContext). -->
?  <listener>
?  ?  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
?  </listener>

?  <listener>
?  ?  <listener-class>
?  ?  ?  org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
?  </listener>

?  <filter>
?  ?  <filter-name>springSecurityFilterChain</filter-name>
?  ?  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
?  </filter>

?  <filter-mapping>
?  ?  <filter-name>springSecurityFilterChain</filter-name>
?  ?  <url-pattern>/*</url-pattern>
?  </filter-mapping>

?  <!-- Provides core MVC application controller. See customauth-servlet.xml. -->
?  <servlet>
?  ?  <servlet-name>customauth</servlet-name>
?  ?  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
?  ?  <load-on-startup>1</load-on-startup>
?  </servlet>

?  <servlet-mapping>
?  ?  <servlet-name>customauth</servlet-name>
?  ?  <url-pattern>*.htm</url-pattern>
?  </servlet-mapping>

?  <servlet-mapping>
?  ?  <servlet-name>customauth</servlet-name>
?  ?  <url-pattern>*.do</url-pattern>
?  </servlet-mapping>

?  <welcome-file-list>
?  ?  <welcome-file>index.jsp</welcome-file>
?  </welcome-file-list>

</web-app>

回答by tomaytotomato

For starters you are using illegal characters inside your XML node param-value

首先,您在 XML 节点参数值中使用了非法字符

You are not allowed to use "/", "<" and other chars inside a node as it will break the parsing of the XML document.

不允许在节点内使用“/”、“<”等字符,因为这会破坏 XML 文档的解析。

You should be using CDATA or PCDATA wrappers around your value inside the XML node.

您应该在 XML 节点内的值周围使用 CDATA 或 PCDATA 包装器。

e.g.

例如

    <param-value><![CDATA[
?      ?  WEB-INF/applicationContext.xml
?      ?  WEB-INF/applicationContext-security.xml]]>
    </param-value>

This was what was causing your problem.

这就是导致您出现问题的原因。

回答by Tamas

Some non-visible characters are not considered XML white space, therefore the error is displayed. Display all the white space characters by configuring the Eclipse "Text Editor" preferences, then the rouge characters will stand out. You can also use this tool to validate your XML file:

一些不可见的字符不被视为 XML 空白,因此会显示错误。通过配置Eclipse“文本编辑器”首选项显示所有空白字符,然后胭脂字符将脱颖而出。您还可以使用此工具来验证您的 XML 文件:

xmllint --noout --schema http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd XML_FILE

回答by TiyebM

You are commenting a closing tag, look again at <filter-mapping>:

您正在评论结束标记,请再次查看<filter-mapping>

 <filter-mapping>
 <filter-name>springSecurityFilterChain</filter-name>
 <url-pattern>      /*</url-pattern> 
 </filter-mapping>`

回答by Victor Mwenda

This error just means you have a typoin your xml. Try formattingyour XML and your typo will stand out.

此错误仅表示您的 xml 中有错字。尝试格式化你的 XML,你的错字会很明显。