initialize ServletContext using a method on a Resin server
Is there a way to initialize 开发者_Python百科the ServletContext for a webapp on a Resin server using a method? I need something like that runs once, when the server starts up.
You need to use a ServletContextListener
.
http://www.java-tips.org/java-ee-tips/java-servlet/how-to-work-with-servletcontextlistener.html
This J2EE tip demonstrates use of ServletContextListener. This event class handles notifications about changes to the servlet context of the Web application that they are part of. This can be explained as if someone is present on the server and dynamically informing us about the events that are occuring on the server. There acquire need of Listners. Therefore, ServletContextListner is helpful in informing about context Initilazation and destruction.
Use the <load-on-startup/>
in the <servlet>
tag.
精彩评论