XML验证缺少标签

时间:2011-02-14 11:30:38

标签: xml validation spring-security

这些xml验证结果实际上代表什么?

“nbres:/org/netbeans/modules/j2ee/ddloaders/catalog/resources/datatypes.dtd”中的引用实体。 cvc-complex-type.2.4.a:从元素'filter-name'开始发现无效内容。其中一个'{“http://java.sun.com/xml/ns/javaee":description,"http://java.sun.com/xml/ns/javaee":display-name,"http:/ /java.sun.com/xml/ns/javaee":icon,"http://java.sun.com/xml/ns/javaee":servlet-name}'是预料之中的。 [48] 元素类型“servlet”必须由匹配的结束标记“”终止。 [50] XML验证完成。

我对这些不太熟悉!

我的档案:

<?xml version="1.0" encoding="UTF-8"?> 
 <web-app 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>KeyCard</display-name>
- <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml
  /WEB-INF/tilesViewContext.xml
  /WEB-INF/ldap-config.xml
   /WEB-INF/security-config.xml
    /WEB-INF/idm-config.xml
  </param-value>
  </context-param>

 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
 <filter>
  <filter-name>charsetFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
 <init-param>
  <param-name>encoding</param-name>
  <param-value>UTF-8</param-value>
  </init-param>
 <init-param>
  <param-name>forceEncoding</param-name>
  <param-value>true</param-value>
  </init-param>
  </filter>

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



 <filter-mapping>
  <filter-name>charsetFilter</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
 <servlet>

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

<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>

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

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


  <servlet-name>KeyCard</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
  </servlet>
 <servlet-mapping>
  <servlet-name>KeyCard</servlet-name>
  <url-pattern>*.html</url-pattern>
  </servlet-mapping>


 <session-config>
  <session-timeout>120</session-timeout>
  </session-config>
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  </web-app>

2 个答案:

答案 0 :(得分:0)

您是否手动编写了此xml代码?

错误消息告诉您XML根据预期的架构无效:

  1. <filter-name>所在的位置<description><display-name><icon><servlet-name>
  2. 您的</servlet>标记(或可能是开头<servlet>)似乎位于错误的位置
  3. 编辑:我在Oxygen中加载了XML,看起来<servlet>的问题实际上是因为<filter>之后的{{1}}标记放错位置。

答案 1 :(得分:0)

今天我遇到了类似的错误。我的代码如下所示:

<servlet>
    <init-param>
        <param-name>data1</param-name>
        <param-value>value1</param-value>
    </init-param>
    <init-param>
        <param-name>data2</param-name>
        <param-value>value2</param-value>
    </init-param>
    <servlet-name>ServletConfigServlet</servlet-name>
    <servlet-class>com.netease.server.example.web.controller.ServletConfigServlet</servlet-class>
</servlet>

错误警告:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. 
One of '{"http://java.sun.com/xml/ns/javaee":description,
"http://java.sun.com/xml/ns/javaee":display-name,
"http://java.sun.com/xml/ns/javaee":icon,
"http://java.sun.com/xml/ns/javaee":servlet-name}' is expected.

我尝试了一些解决方案。最后,我修改了更改了 <init-param><servlet-name>, <servlet-class>的顺序。它看起来像:

<servlet>
    <servlet-name>ServletConfigServlet</servlet-name>
    <servlet-class>com.netease.server.example.web.controller.ServletConfigServlet</servlet-class>
    <init-param>
        <param-name>data1</param-name>
        <param-value>value1</param-value>
    </init-param>
    <init-param>
        <param-name>data2</param-name>
        <param-value>value2</param-value>
    </init-param>
</servlet>

希望这可以帮助某人。 :d