首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么web.xml 'context-param‘不能有字符[子]?

为什么web.xml 'context-param‘不能有字符[子]?
EN

Stack Overflow用户
提问于 2013-03-13 22:26:38
回答 3查看 15.2K关注 0票数 7

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

代码如下:

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

回答 3

Stack Overflow用户

发布于 2013-04-10 21:38:09

对于初学者,您在XML节点param-value中使用了非法字符

不允许在节点中使用"/“、"<”和其他字符,因为它们会破坏XML文档的解析。

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

例如:

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

这就是导致你的问题的原因。

票数 9
EN

Stack Overflow用户

发布于 2013-10-08 00:29:03

一些不可见的字符不被视为XML空白,因此显示错误。通过配置Eclipse "Text Editor“首选项来显示所有空格字符,然后红色字符将会突出显示出来。您还可以使用此工具来验证XML文件:

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

Stack Overflow用户

发布于 2016-05-24 01:02:28

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

 <filter-mapping>
 <filter-name>springSecurityFilterChain</filter-name>
 <url-pattern>      /*</url-pattern> 
 </filter-mapping>`
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15388084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档