package com.gopersist.demo.servlet3.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 按照loadOnStartup的设定，Tomcat在启动时，会先加载数字小的Servlet，
 * 加载时，先实例化，再执行init()
 */
@WebServlet(
		name="demoServlet1", 
		urlPatterns={"/servlet3/servlet/demo1", "/servlet3/servlet/demo1/*"}, 
		loadOnStartup=1, 
		initParams={@WebInitParam(name="msg", value="Hello servlet 1!")}
		)
public class DemoServlet1 extends HttpServlet {
	private String msg;
	
	public DemoServlet1 () {
		System.out.println("[DemoServlet1] DemoServlet1()");
	}
	
	@Override
	public void init() throws ServletException {
		super.init();
		System.out.println("[DemoServlet1] init()");
		msg = this.getInitParameter("msg");
	}
	
	@Override
    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("[DemoServlet1] doGet(): " + msg);
        resp.getWriter().append(msg).close();
    }
}

@@ -384,16 +384,65 @@
 ervlet%EF%BC%8C%0A
+ * %E5%A6%82%E6%9E%9CloadOnStartup%E6%B2%A1%E6%9C%89%E8%AE%BE%E5%AE%9A%EF%BC%8C%E4%BC%9A%E5%9C%A8%E8%AE%BF%E9%97%AEServlet%E6%97%B6%E6%89%8D%E5%8A%A0%E8%BD%BD%E8%BF%99%E4%B8%AAServlet%EF%BC%8C%0A
  * %E5%8A%A0%E8%BD%BD%E6%97%B6%EF%BC%8C%E5%85%88

Add description for loadOnStartup.