当我不使用全局命名空间时为什么web.xml不起作用? [英] Why web.xml does not work when I do not use a global namespace?
问题描述
我有这个非常简单的web.xml文件:
I have this very simple web.xml file:
<?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:
When I deploy the application and visit the context root, I will be taken to testx.jsp which is fine. But in my web.xml file I do not want to use a global namespace so I change the web.xml as follows:
<?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。但为什么?
Now when I again start tomcat and visit the page, I will find myself in /index instead of /testx.jsp. But why?
我正在将应用程序部署到Tomcat服务器。我试过Glassfish,但我没有遇到这个问题。我想这是一个Tomcat问题?
I am deploying the application to Tomcat Server. I tried Glassfish and I did not encounter this problem. I guess this is a Tomcat problem?
推荐答案
你的XML是正确有效的,但 xmlNamespaceAware
您的Tomcat Web应用程序的属性Context可能设置为false(默认值)。
Your XML is correct and valid, but the xmlNamespaceAware
property of your Tomcat web application Context is probably set to false (default).
我能够重现您使用Web描述的行为。对于元素使用名称空间前缀的xml,就像您的示例一样。修改%CATALINA_HOME%/ conf / context.xml
后,将xmlNamespaceAware属性设置为true < Context xmlNamespaceAware =true>
,welcome-file-list的行为符合预期。
I was able to reproduce the behavior you describe with a web.xml that uses namespace-prefixes for the elements, like your example. After modifying the %CATALINA_HOME%/conf/context.xml
to add the xmlNamespaceAware attribute set to true <Context xmlNamespaceAware="true">
, the welcome-file-list behaved as expected.
https://tomcat.apache.org/tomcat-7.0-doc/config/context.html
xmlNamespaceAware
如果此标志的值为true,则解析web.xml此Web应用程序的
web-fragment.xml文件将是
名称空间感知。请注意,* .tld,* .jspx和* .tagx文件始终使用名称空间感知解析器解析
,并且从不使用名称空间感知解析tagPlugins.xml文件
(如果有)解析器。另请注意
如果你打开这个标志,你应该也可以打开
xmlValidation。如果org.apache.catalina.STRICT_SERVLET_COMPLIANCE
系统属性设置为true,则此属性
的默认值为true,否则默认值为false。将此
属性设置为true将导致性能下降。
If the value of this flag is true, the parsing of web.xml and web-fragment.xml files for this web application will be namespace-aware. Note that *.tld, *.jspx and *.tagx files are always parsed using a namespace-aware parser and that the tagPlugins.xml file (if any) is never parsed using a namespace-aware parser. Note also that if you turn this flag on, you should probably also turn xmlValidation on. If the org.apache.catalina.STRICT_SERVLET_COMPLIANCE system property is set to true, the default value of this attribute will be true, else the default value will be false. Setting this attribute to true will incur a performance penalty.
这篇关于当我不使用全局命名空间时为什么web.xml不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!