2014-11-02 56 views
2

我有這個非常簡單的web.xml文件:當我不使用全局名稱空間時,爲什麼web.xml不起作用?

<?xml version="1.0" encoding="UTF-8" ?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 
    <welcome-file-list> 
     <welcome-file>testx.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

當我部署應用程序和訪問上下文根,我將採取testx.jsp這是罰款。但在我的web.xml文件,我不希望使用一個全局命名空間,所以我改變了web.xml如下:

<?xml version="1.0" encoding="UTF-8" ?> 
<ee:web-app xmlns:ee="http://xmlns.jcp.org/xml/ns/javaee" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
      version="3.1"> 
    <ee:welcome-file-list> 
     <ee:welcome-file>testx.jsp</ee:welcome-file> 
    </ee:welcome-file-list>  
</ee:web-app> 

現在,當我重新啓動Tomcat,訪問該頁面,我會發現自己在/索引而不是/testx.jsp。但爲什麼?

我正在將應用程序部署到Tomcat服務器。我嘗試了Glassfish,但沒有遇到這個問題。我想這是一個Tomcat問題?

回答

2

您的XML是正確且有效的,但Tomcat Web應用程序Context的xmlNamespaceAware屬性可能設置爲false(默認)。

我能夠重現你所描述的行爲,使用名稱空間前綴作爲元素的web.xml,就像你的例子。在修改%CATALINA_HOME%/conf/context.xml以添加設置爲true的xmlNamespaceAware屬性<Context xmlNamespaceAware="true">後,welcome-file-list按預期工作。

https://tomcat.apache.org/tomcat-7.0-doc/config/context.html

xmlNamespaceAware

如果這個標誌的值爲true,web.xml中的 網絡fragment.xml之文件的解析,併爲此Web應用程序將是 namespace-知道的。請注意,* .tld,* .jspx和* .tagx文件始終使用支持命名空間的解析器進行分析,並且從不使用支持名稱空間的解析器對tagPlugins.xml文件 (如果有)進行分析。還請注意 如果您打開此標誌,您應該也可以打開 xmlValidation。如果org.apache.catalina.STRICT_SERVLET_COMPLIANCE 系統屬性設置爲true,則此屬性的默認值爲 將爲true,否則默認值爲false。將此 屬性設置爲true將導致性能損失。

+0

爲什麼會在默認情況下關閉? – 2014-11-04 06:57:17

相關問題