public class initCounter extends HttpServlet {
int count;
public void init(ServletConfig config) throws ServletException {
super.init(config); // purpose of this method ?
String initial = config.getInitialParameter("initial");
}
}
In the method init what does the argument ServletConfig indicate ? What it is for ? What does the call super.init(config) do ? What is the purpose of this statement ?
I read that the method getInitialparameter return the initial paramater, but what is a initial param
It’s passed by the container to the servlet in order for the servlet to be able to store it, and call any of its methods.
The purpose of
super.init(config)is to make sure that, although the method is overridden, the base implementation is nevertheless called.See the javadoc of the method:
An init parameter is a parameter that may be pased to the servlet thanks to the deployment descriptor (web.xml file) of the web app: