Originally posted by yogendra singh:
I also have one thing to know....
if we override the init(config) method . and dont call the super(config) ..what wud happen...will the instance of servlet will get created or not.. is this mandatory.
You shouldn't see any drastic result unless you call getInitParameter() method outside the init(ServletConfig).
a) init(ServletConfig config) {
super.init(config)
String initParam = config.getInitParameter();//should be able to get the init param set in web.xml
}
service(ServletRequest req,ServletResponse res){
String initParam = getInitParameter()();//should be able to get the init param set in web.xml
}
b) init(ServletConfig config) {
String initParam = config.getInitParameter();//should be able to get the init param set in web.xml
}
service(ServletRequest req,ServletResponse res){
String initParam = getInitParameter()();//get Exception here.Coz the getInitParameter method of GenericServlet is being called without setting the config info to it.
}
The reason for calling super.init(config) is pass on the servlet config information to the generic servlet and hold the reference. This information can be retrieved from methods other than init() later on.
Thanks,
Moorthi