Why do we need to override the init () method in Servlets, while we can initialize in the constructor and have a web container that calls the constructor, passing the ServletConfig link to the servlet when the constructor is called?
The exchange container must use reflection for this, but the container must use reflection in any case to invoke a simple no-arg constructor
, "" API Servlet, . , Java , destroy, init API .
destroy
init
/ , .
, . , . . Servlet.
, http://oreilly.com/catalog/jservlet/chapter/ch03.html :
init() - , . ? , JDK 1.0 ( ) Java (, ) ., , init() , ServletConfig., Java . , javax.servlet.Servlet , ServletConfig. , init(). , , ServletConfig ServletException.
init() - , . ? , JDK 1.0 ( ) Java (, ) .
, , init() , ServletConfig.
, Java . , javax.servlet.Servlet , ServletConfig. , init(). , , ServletConfig ServletException.
, ServletConfig . ServletConfig init(). , .
, init() Servlet - : Java, , , Servlet -, Servlet ServletConfig , , ServletContext, .
- , javax.servlet, HttpServlet - , , Java, , Java. , . , Servlet , Java-, . -, Tomcat Jetty, Java Reflection Servlet, . , , - , . , Java , . Servlet.
Source: https://habr.com/ru/post/1747346/More articles:The best and shortest books in C ++ / STL / C # / J2SE to prepare for work inteview / tests - c ++How good is the circular memory buffer on Wikipedia? - cplaying mp3 file using jquery - javascriptGetting the location of the .bat file from within - windowsWPF, White and Infragistics - testing projectОтображение таблиц из существующей базы данных в объект - подходит ли Hibernate? - javaHTML Why do iframe contents load twice? - htmlCSS line break in TD - cssLive feedback on how many characters are left in the text box - javascriptWorks in Firefox but not IE - javascriptAll Articles