Class implementing ServletContainerInitializer in web.xml

对着背影说爱祢 提交于 2019-12-22 10:57:25

问题


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.


回答1:


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/



来源:https://stackoverflow.com/questions/7680860/class-implementing-servletcontainerinitializer-in-web-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!