Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Servlet object has a well-defined life cycle where creation and initialization steps are distinct. Usually you don't want to do heavy and unreliable work in constructors, e.g. getting DB connection pool or initializing cache. You have a chance to do it after a Servlet object is successfully created.</p> <p>Also, here <a href="http://oreilly.com/catalog/jservlet/chapter/ch03.html" rel="noreferrer">http://oreilly.com/catalog/jservlet/chapter/ch03.html</a> is a historical reason:</p> <blockquote> <p>The init() method is typically used to perform servlet initialization--creating or loading objects that are used by the servlet in the handling of its requests. <strong>Why not use a constructor instead?</strong> Well, in JDK 1.0 (for which servlets were originally written), constructors for dynamically loaded Java classes (such as servlets) couldn't accept arguments. </p> <p>So, in order to provide a new servlet any information about itself and its environment, a server had to call a servlet's init() method and pass along an object that implements the ServletConfig interface. </p> <p>Also, Java doesn't allow interfaces to declare constructors. This means that the javax.servlet.Servlet interface cannot declare a constructor that accepts a ServletConfig parameter. It has to declare another method, like init(). It's still possible, of course, for you to define constructors for your servlets, but in the constructor you don't have access to the ServletConfig object or the ability to throw a ServletException.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload