Can load-on-startup in web.xml be used to load an arbitrary class on startup?

后端 未结 4 786
旧时难觅i
旧时难觅i 2020-12-28 17:45

How can I load an arbitrary class on startup in Tomcat? I saw load-on-startup tag for web.xml file, but can I use it and how should I implement my

4条回答
  •  孤城傲影
    2020-12-28 18:10

    enfix,

    Your XML looks good.

    You should place a init() method in your servlet class, that gets called when your server bootsup. doGet, doPost and do methods get called only when there is an incoming request.

    public class YourServlet extends HttpServlet
    {
        public void init()
        {
            //initialize( or add a log statement to debug)
        }
    }
    

提交回复
热议问题