在前面一篇文章 “【新手记录】servlet的初始
化init方法什么时候被调用?
”中用实例验证了下servlet的init方法何时被调用,虽然有了测试结果。
不过还是感觉不放心,于是到sun官方网站看了下servlet的specification。
得到了肯定的答复:
首先是J2EE api里对servlet的init方法的说明:
init
void init(ServletConfig config)
throws ServletException
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
The servlet container calls the init method exactly once after instantiating the servlet. The init method must complete successfully before the servlet can receive any requests.
The servlet container cannot place the servlet into service if the init method
Throws a ServletException
Does not return within a time period defined by the Web server
然后又看了下Java™ Servlet Specification Version 2.5 MR6的详细说明
The load-on-startup element indicates that this
servlet should be loaded (instantiated and have
its init() called) on the startup of the web
application. The optional contents of these
element must be an integer indicating the order in
which the servlet should be loaded. If the value
is a negative integer, or the element is not
present, the container is free to load the servlet
whenever it chooses. If the value is a positive
integer or 0, the container must load and
initialize the servlet as the application is
deployed. The container must guarantee that
servlets marked with lower integers are loaded
before servlets marked with higher integers. The
container may choose the order of loading of
servlets with the same load-on-start-up value
If the value is a negative integer, or the element is not present, the container is free to load the servlet
whenever it chooses. If the value is a positive
integer or 0, the container must load and initialize the servlet as the application is deployed.
如果是负数,或者没有标识load-on-startup参数,这个就有容器自己去选择是否加载了。如果是正数或者0,
那么容器在应用部署的时候就必须要初始化这个servlet。
好吧,不写或者为负数还是有意外的啊!看来还是找specification查东西靠谱。
分享到:
相关推荐
Java Servlet Specification__ Version 2.3书籍
最新的servlet3.0规范和api文档
The intended audience for this specification includes the following groups:vi Java Servlet Specification • April 2013 ■ Web server and application server vendors that want to provide servlet engines...
JSP开发Servlet重写init()方法实例详解 写一个Servlet时,有时需要我们重写该Servlet的初始化方法,然后,究竟是重写init(ServletConfig config),还是重写init(),这是个问题。要明了这一点,首先要知道Servlet的...
Java+Servlet+Specification+2.4
java servlet-3-1-specification规范的中文版,介绍了什么servlet
Domino中使用Servlet!~~~~~~!!~~
servlet的规范.英文
自己写的用于Servlet转码 charset包下charset类里的charset方法传入参数,返回经过utf-8转码的信息 注:主要用于Servlet中的doGet方法
servlet 中文说明 API javax.servlet.Servlet接口 方法说明~!
Servlet3.1官方文档翻译版本,详细描述sevlet技术规范的方方面面......
比较适合初学者的servlet和jsp教程~
里面有关于jsp/servlet的所有内置方法,有方法名,方法注释,讲解得非常详细
缺省的 init() 方法设置了 Servlet 的初始化参数,并用它的 ServletConfig 对象参数来启动配置, 因此所有覆盖 init() 方法的 Servlet 应调用 super.init() 以确保仍然执行这些任务。在调用 service() 方法之前,应...
文档中包含servlet中的方法 及接口的介绍。
Ch1_Servlet~~~~Ch6_SessionBindingActivationListeners~~~~Ch10_SimpleTagHandler~~~Ch10_SimpleTagHandlerWithBody~~~Ch10_SimpleTagHandlerWithExpression~~Ch10_SimpleTagHandlerWithIteratingTheBody~~~Ch10_...
用注解的方式定义一个Servlet,就不用在web.xml中配置了。Servlet的访问URL是Servlet的必选属性,可以选择使用urlPatterns或者value定义。 像上面的AnnotationServlet可以描述成@WebServlet(name="Annotation...
开发servlet有三种方法的实现: 1.实现servlet接口 2.继承GenericServlet 3.继承HttpServlet
Servlet接口的基本目标是提供生命期方法init()、service()和destroy()方法。 servlet接口中的方法 void init(ServletConfit config)throws ServletException 在servlet被载入后和实施服务前由servlet引擎进行?次性...