如标题所示,带前缀“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>
最佳答案
阅读下面的 xml 命名空间。这是 xml 的基础知识。
因此,在您的 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 的工作方式。没有别的了。
关于java - web.xml 中前缀为 "javaee:"的标签与不包含前缀 "javaee:"的标签有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40522761/