Example & Tutorial understanding programming in easy ways.

Can constructor be used instead of init(), to initialize servlet?

Yes, it is possible. But it is not preferred because init() was developed because earlier Java versions could not invoke constructors with arguments dynamically. So they could not assign a servletConfig. Today, however, servlet containers still call only no-arg constructor. So there is no access to servletContext or servletConfig.

Read More →