search

Home  >  Q&A  >  body text

java - What is the difference between the init method of servlet and the init method of selecting Filter to load the configuration file?

springMVC chooses the init method of servlet to load the configuration file, while jfinal chooses the init method of Filter to load the configuration file

  1. What is the difference between the two?

  2. What are the reasons or advantages for this choice?

仅有的幸福仅有的幸福2793 days ago912

reply all(2)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-17 10:09:44

    The call of

    Filterinit方法一定会在容器启动的时候执行,但Servletinit方法未必,要看load参数是怎么写的,默认的话,只有该Servlet首次被访问(访问路径匹配了urlMapping)才会触发init.

    Also, compared to two init,我更喜欢把所有的初始化工作放在ServletContextListenercontextInitializedri.

    reply
    0
  • 某草草

    某草草2017-05-17 10:09:44

    I also observed it some time ago, and I don’t quite understand that the execution order of filter and servlet is one before the other. I wonder if I chose to use servlet or filter due to design reasons

    reply
    0
  • Cancelreply