2013-03-13 4 views
6

Tôi chỉ tò mò điều gì xảy ra với mã này web.xml nơi tôi gặp lỗi này cvc-complex-type.2.3: Element 'context-param' cannot have character [children], because the type's content type is element-only. trong chế độ xem Eclipse (phiên bản juno) Markers.Tại sao web.xml 'context-param' không thể có ký tự [children]?

Đây là mã:

<?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> 
+0

vì DTD không cho phép yếu tố đó để có con? –

+0

Đặc biệt, Servlet Specefication 2.5 cho phép param-name và param-value. Có lẽ đó là một vấn đề của Eclipse –

+0

Tôi không chắc nguyên nhân gốc rễ của việc này là gì, tôi chỉ từ bỏ dự án và tái tạo lại. – huahsin68

Trả lời

9

Đối với người mới bắt đầu bạn đang sử dụng các nhân vật bất hợp pháp bên trong XML nút param-value

Bạn không được phép sử dụng "/", "<" của bạn và ký tự khác bên trong một nút vì nó sẽ phá vỡ phân tích cú pháp của tài liệu XML.

Bạn nên sử dụng trình bao bọc CDATA hoặc PCDATA xung quanh giá trị của bạn bên trong nút XML.

ví dụ:

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

Đây là nguyên nhân gây ra sự cố của bạn.

+3

Ký tự '/' là một ký tự hợp lệ bên trong một nút XML. – Tamas

+2

Câu trả lời hay, mặc dù "/" đã gây hiểu lầm (đủ rõ ràng). Vấn đề của tôi là @ -characters trong một giá trị tham số. – MrLymy

+0

cảm ơn bạn đã chọn con trỏ. Trong trường hợp của tôi, đó là vì một nhân vật đi lạc trong yêu cầu. Tôi nghĩ rằng lỗi này không phải là cụ thể, bất cứ điều gì sai có thể gây ra nó. –

2

Một số ký tự không hiển thị không được coi là không gian trắng XML, do đó lỗi được hiển thị. Hiển thị tất cả các ký tự khoảng trắng bằng cách cấu hình các tùy chọn "Trình soạn thảo văn bản" của Eclipse, sau đó các ký tự rouge sẽ nổi bật. Bạn cũng có thể sử dụng công cụ này để xác thực tệp XML của bạn:

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

Bạn đang bình luận một thẻ đóng, hãy tìm một lần nữa tại <filter-mapping>:

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