缺少有效web.xml中web-fragment.xml的元素 [英] Missing elements from web-fragment.xml in the effective web.xml
问题描述
在我们的项目中,我们使用web片段来定义一些servlet,以便可以在其他项目中轻松使用工件。
In our project we make use of web-fragments to define some servlets so the artifacts easily can be used in other projects.
现在奇怪的是我们有一个web-fragment.xml,但它的一些内容没有被添加到有效的web.xml中。
Strange thing now is that we have a web-fragment.xml, but some of its contents doesn't get added to the effective web.xml.
例如:
有效的web.xml中存在以下配置:
The following configurations is present in the effective web.xml:
<filter>
<filter-name>superUserAutomaticLogon</filter-name>
<filter-class>nl.caiw.cool.util.filters.SuperUserAutomaticLogonFilter</filter-class>
<async-supported>false</async-supported>
</filter>
但以下情况并非如此:
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/toolbox/modules/*</url-pattern>
</filter-mapping>
我们尝试了几件事,但我们无法理解。希望有人可以向我们发送正确的方向。
We have tried several things, but we can't figure it out. Hopefully someone here can send us in the right direction.
提前致谢。
推荐答案
现在奇怪的是我们有一个web-fragment.xml,但是它的一些内容没有被添加到有效的web.xml中。
Strange thing now is that we have a web-fragment.xml, but some of its contents doesn't get added to the effective web.xml.
首先, web-fragment.xml
无法实现物理包含在主 web.xml
中。所以当你说它没有被添加到有效的 web.xml
时,我觉得你可能会出错。
Well first of all, a web-fragment.xml
wouldn't get physically included into the main web.xml
. So when you say it doesn't get added to the effective web.xml
, I feel you may be going wrong there.
Web片段允许组件在运行时将自己注册到主 web.xml
。你会发现这个事件的唯一证据是实际上试图使用这个组件。
Web fragments allow compoments to register themselves to the main web.xml
at runtime. The only evidence you will find of this happening is by actually trying to use the compoment.
我尝试了一个简单的hello-world示例,其中包含Web片段并让它工作。我使用Servlet 3.0 webapp使用Tomcat 7。
I tried out a simple hello-world example with web fragments and got it to work. I used Tomcat 7 for this with a Servlet 3.0 webapp.
我的主 web.xml
在<$ c $里面c> WEB-INF 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>hello-world</display-name>
<absolute-ordering>
<name>filters</name>
</absolute-ordering>
</web-app>
我发现我们唯一可以注册一个网络片段。 xml
遵守以下规则:
I figured out that the only wey we could register a web-fragment.xml
was by adhering to the below rules:
- 必须将其命名为
web- fragment.xml
- 它必须放在
WEB-INF / lib
里面的JAR文件中 -
web-fragment.xml
必须出现在META-INF
目录中JAR文件。
- It must be named
web-fragment.xml
- It must be placed in a JAR file inside
WEB-INF/lib
- The
web-fragment.xml
must be present inside theMETA-INF
directory of the JAR file.
我的 web-fragment.xml
如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd" id="WebAppFragment_ID" version="3.0">
<name>filters</name>
<filter>
<filter-name>interceptor</filter-name>
<filter-class>com.adarshr.Interceptor</filter-class>
</filter>
<filter-mapping>
<filter-name>interceptor</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-fragment>
通过上述最小设置,我能够获得拦截器
过滤器被触发,虽然它被放在 web-fragment.xml
中。
With the above minimal setup, I was able to get the Interceptor
filter to get fired, though it was placed in the web-fragment.xml
.
最后,这是我的目录结构(使用 http://www.adarshr.com/treegen 生成)
Finally, here is my directory structure (generated using http://www.adarshr.com/treegen)
+- hello-world
|
+- WEB-INF
|
+- lib
| |
| |- my-library.jar
|
|- web.xml
JAR文件 my-library .jar
具有以下结构:
The JAR file my-library.jar
has the below structure:
+- my-library.jar
|
+- META-INF
|
|- web-fragment.xml
一些参考文献:
- https://blogs.oracle.com/swchan/entry / servlet_3_0_web_fragment
- http://java.sun .com / developer / technicalArticles / JavaEE / JavaEE6Overview_Part2.html
- https://blogs.oracle.com/swchan/entry/servlet_3_0_web_fragment
- http://java.sun.com/developer/technicalArticles/JavaEE/JavaEE6Overview_Part2.html
这篇关于缺少有效web.xml中web-fragment.xml的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!