Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

java - "Servlet" (server-side) initialization code in GWT

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(), but old habits are long to lose ;)

What I am trying to do is:

  • load a bunch of properties

  • establish a connection to the database

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 :

<listener>
<listener-class>path.to.class.ServerConfig</listener-class> 
</listener>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...