问题描述
你能指出一个在 web.xml
文件中实现 ServletContainerInitializer
接口的类,或者你是否需要在 META-INF / services / javax.servlet.ServletContainerInitializer
下添加一个文件让J2EE服务器拿起它?
如果可以通过 web.xml
文件,请解释如何。
我已经检查了,但我没有发现任何线索它可以通过 web.xml
进行配置。我认为唯一的方法是
META-INF / services / javax.servlet.ServletContainerInitializer
文件。
META-INF / services / javax.servlet.ServletContainerInitializer 是一个文件(不是目录),必须包含initalizer的完全限定名称,喜欢:
com.example.MyServletContainerInitializer
它也可能在战争中(用Tomcat 7.0.21测试)。
这是一个完整的例子:
Can you point to a class implementing the ServletContainerInitializer
interface in the web.xml
file or do you have to add a file under the META-INF/services/javax.servlet.ServletContainerInitializer
to have a J2EE server pick it up?
If it's possible via the web.xml
file, please explain how.
I've checked the Java Servlet Specification 3.0 and I've not found any clue that it could be configured via web.xml
. I think the only way is the META-INF/services/javax.servlet.ServletContainerInitializer
file.
Please note that the META-INF/services/javax.servlet.ServletContainerInitializer
is a file (not a directory) which has to contain the fully qualified name of the initalizer, like:
com.example.MyServletContainerInitializer
It could be inside the war too (tested with Tomcat 7.0.21).
Here is a complete example: http://nullhaus.com/2011/03/using-servlets-3-0-servletcontainerinitializer/
这篇关于在web.xml中实现ServletContainerInitializer的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!