“Servlet” (server-side) initialization code in GWT

后端 未结 2 939
清歌不尽
清歌不尽 2020-11-28 16:04

How can I have a single time initialization on a server side of GWT app?

I may be thinking to much like HttpServlet where you can override init()

2条回答
  •  伪装坚强ぢ
    2020-11-28 16:57

    You can add like mentioned in a comment a ServletContextListener.

    public class ServerConfig implements ServletContextListener {
    
        public void contextInitialized(ServletContextEvent event) {
        // Do stuff on startup.
        }
    
        public void contextDestroyed(ServletContextEvent event) {
        // Do stuff on shutdown.
        }
    }
    

    Now put the new class on the server side, you also ave to register the Listener in your web.xml file :

    
    path.to.class.ServerConfig 
    
    

提交回复
热议问题