2016-11-10 74 views
1

作爲標題,帶有前綴「javaee:」的標籤和不帶「javaee:」的標籤之間有什麼區別。web.xml中帶有前綴「javaee:」的標籤和「javaee:」不帶有什麼區別?

我覺得我們需要使用標籤,而不設置配置「JavaEE的:」與前綴標籤「的JavaEE:」不工作

例如:

<welcome-file-list> 
    <welcome-file>default.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
</welcome-file-list> 

工作

<javaee:welcome-file-list> 
    <javaee:welcome-file>default.jsp</javaee:welcome-file> 
    <javaee:welcome-file>default.html</javaee:welcome-file> 
</javaee:welcome-file-list> 

不起作用。

我使用tomcat 8.5.6作爲服務器。下面

是我的web.xml:

<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xml="http://www.w3.org/XML/1998/namespace" 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_3_0.xsd "> 
    <display-name>SQUEEN WECHAT</display-name> 

    <welcome-file-list> 
     <welcome-file>default.jsp</welcome-file> 
     <welcome-file>default.html</welcome-file> 
    </welcome-file-list> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      WEB-INF/config/spring/applicationContext.xml 
     </param-value> 
    </context-param> 

    <context-param> 
     <param-name>log4jConfigLocation</param-name> 
     <param-value>WEB-INF/config/log4j.properties</param-value> 
    </context-param> 

    <listener> 
     <listener-class> 
      org.springframework.web.util.Log4jConfigListener 
     </listener-class> 
    </listener> 

    <listener> 
     <listener-class> 
      org.springframework.web.context.ContextLoaderListener 
     </listener-class> 
    </listener> 
</web-app> 
+0

顯示您的完整web.xml特別是開始標籤聲明,我會解釋.. –

回答

1

閱讀下面的XML命名空間。這是xml的基礎。

enter image description here

所以在你的web.xml如果聲明類似如下:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> 

你可以寫下面沒有命名空間。

<welcome-file-list> 
    <welcome-file>default.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
</welcome-file-list> 

如果您的web.xml看起來像如下的具有自定義命名空間聲明

注:的xmlns:JavaEE的):

<web-app xmlns:javaee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> 

你寫的與命名空間相同如下:

<javaee:welcome-file-list> 
    <javaee:welcome-file>default.jsp</javaee:welcome-file> 
    <javaee:welcome-file>default.html</javaee:welcome-file> 
</javaee:welcome-file-list> 

這只是xml如何工作的方式。沒有其他的。