Example to Override the init() method of the servlet

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with 1 Comment on Example to Override the init() method of the servlet

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.

Related posts

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

Leave a Reply

Your email address will not be published. Required fields are marked *