Example to Override the init() method of the servlet

It is not recommended to override the init() method of the servlet.

Here is an example to override init() method of servlet:

    public class BookDBServlet ... {

        private BookstoreDB books;

        public void init(ServletConfig config) throws ServletException {

            // Store the ServletConfig object and log the initialization
            super.init(config);

            // Load the database to prepare for requests
            books = new BookstoreDB();
        }
        ...
    }

you must write super.init(config) code and after that program specific logic.

Posted

in

by

Tags:


Related Posts

Comments

One response to “Example to Override the init() method of the servlet”

  1. […] Step 3: At Step 2, the Servlet object is just normal java object. It is the init() method which is just called after the instantiation of object and gives the Servletness to object. Like applets, this method is called only once in life cycle. It is recommended not to override the init() method but if you want to override then read this arti… […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading