7

我只是好奇这段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视图中出现此错误时发生了什么。

这是代码:

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

4 回答 4

9

对于初学者,您在 XML 节点参数值中使用了非法字符

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

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

例如

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

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

于 2013-04-10T13:38:09.027 回答
2

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

xmllint --noout --schema http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd XML_FILE
于 2013-10-07T16:29:03.183 回答
0

此错误仅表示您的 xml 中有错字。尝试格式化您的 XML,您的拼写错误将脱颖而出。

于 2019-03-18T20:06:01.403 回答
0

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

 <filter-mapping>
 <filter-name>springSecurityFilterChain</filter-name>
 <url-pattern>      /*</url-pattern> 
 </filter-mapping>`
于 2016-05-23T17:02:28.390 回答