为什么web.xml的“context-param”不能有字符[children]? [英] Why web.xml 'context-param' cannot have character [children]?
问题描述
我只是好奇,这个 web.xml
代码发生了什么,我有这个错误 cvc-complex-type.2.3:元素的上下文-param'不能包含字符[children],因为类型的内容类型是仅元素。在Eclipse(juno版本)
。 标记
视图中的
这是代码:
<?xml version = 1.0encoding =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的/网络app_2_5.xsd>
< display-name> Spring安全Web应用程序(系列)< / display-name>
<! - 具体停止tomcat上多个应用程序的麻烦 - >
< context-param>
< param-name> webAppRootKey< / param-name>
< param-value> customauth_root< / param-value>
< / context-param>
<! - 定义由ContextLoaderListener应用的根应用程序上下文
的XML文件的位置。 - >
< context-param>
< param-name> contextConfigLocation< / param-name>
< param-value>
WEB-INF / applicationContext.xml
WEB-INF / applicationContext-security.xml
< / param-value>
< / context-param>
<! - 在启动时加载此Web应用程序的根应用程序上下文。
应用程序上下文可通过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>
<! - 提供核心MVC应用控制器。请参阅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>
对于初学者,您在XML节点中使用非法字符param-value
您不能使用/,<和节点中的其他字符,因为它会破坏XML文档的解析。
您应该在XML节点内的值周围使用CDATA或PCDATA包装。 p>
例如
< param-value><![CDATA [
WEB-INF / applicationContext.xml
WEB-INF / applicationContext-security.xml]]>
< / param-value>
这是导致您的问题。
I am just curious what happen to this web.xml
code 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) Markers
view.
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>
For starters you are using illegal characters inside your XML node param-value
You are not allowed to use "/", "<" and other chars inside a node as it will break the parsing of the XML document.
You should be using CDATA or PCDATA wrappers around your value inside the XML node.
e.g.
<param-value><![CDATA[
WEB-INF/applicationContext.xml
WEB-INF/applicationContext-security.xml]]>
</param-value>
This was what was causing your problem.
这篇关于为什么web.xml的“context-param”不能有字符[children]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!