gpt4 book ai didi

xml - 为什么当我不使用全局命名空间时 web.xml 不起作用?

转载 作者:行者123 更新时间:2023-11-28 21:58:27 24 4
gpt4 key购买 nike

我有这个非常简单的 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 并访问该页面时,我会发现自己位于/index 而不是/testx.jsp。但为什么?

我正在将应用程序部署到 Tomcat 服务器。我试过 Glassfish,但没有遇到这个问题。我想这是 Tomcat 的问题?

最佳答案

您的 XML 正确且有效,但是 xmlNamespaceAware您的 Tomcat Web 应用程序 Context 的属性可能设置为 false(默认)。

我能够使用 web.xml 重现您描述的行为,该 web.xml 对元素使用 namespace 前缀,例如您的示例。修改后%CATALINA_HOME%/conf/context.xml添加 xmlNamespaceAware 属性设置为 true <Context xmlNamespaceAware="true"> ,欢迎文件列表按预期运行。

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

xmlNamespaceAware

If the value of this flag is true, the parsing of web.xml andweb-fragment.xml files for this web application will benamespace-aware. Note that *.tld, *.jspx and *.tagx files are alwaysparsed using a namespace-aware parser and that the tagPlugins.xml file(if any) is never parsed using a namespace-aware parser. Note alsothat if you turn this flag on, you should probably also turnxmlValidation on. If the org.apache.catalina.STRICT_SERVLET_COMPLIANCEsystem property is set to true, the default value of this attributewill be true, else the default value will be false. Setting thisattribute to true will incur a performance penalty.

关于xml - 为什么当我不使用全局命名空间时 web.xml 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26699855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com