loadOnStartup

当loadOnStartup=1时,代表服务一启动就去加载执行实例化这个servlet类,下面是一个小例子:
@WebServlet(urlPatterns={"/myServlet","/testServlet"}
            ,initParams={@WebInitParam(name="def",value="ddeeff")}
            ,loadOnStartup=1)

public class TestServlet extends HttpServlet {
	
	public TestServlet(){
		System.out.println("servlet..loadOnStartup=========构造");
	}

	public void init(ServletConfig config) throws ServletException {
		System.out.println("servlet..loadOnStartup=========init");
	}
	


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("servlet..loadOnStartup=========get");
			}

}

控制台输出结果:

servlet..loadOnStartup=========构造
servlet..loadOnStartup=========init

当在地址栏输入:http://localhost:8080/servlet3/testServlet

则控制台会输出:

servlet..loadOnStartup=========get

 

 

 

 

你可能感兴趣的:(startup)