robert dodson wrote:
"A servlet init parameter cannot have the same name with the servlet it refers to"
I think this is wrong but I dont know where to find out for sure and why its wrong. I think I read it somewhere but I can not find it can anyone explain this to a noob
Hai.. do you mean the life cycle method:public void init(ServletConfig servletconfig){//code}
if so then;please see this:
public void init(ServletConfig servletconfig){
this.config=config;
init();}
the above is the one of the life cycle methods of servlet..(the three life cycle methods of servlet:init(ServletConfig),service(ServletRequest,ServletResponse),destroy() )
a servlet interface contains this as a abstract method and GenericServlet(abstract class) implementing the " javax.servlet.Servlet(interface),javax.servlet.ServletConfig(interface), java.io.Serializable (marker interface)"contains this method.
init(-) method is the lifecycle method of servlet program which is executed by servlet container for instantiation event having ServletConfig object as argument value on our servlet class.since a good programmer will execute keeps his intialization logic of servlet program by overriding "
init()" method and gives chance to inti(-) of GenericServlet class to execute.
the init(-) apart from performing initialization process ,invokes init() method at the end.
ServletCnfig object is the right hand(useful) object for our servlet program.It is one per servlet object.To pass information to servlet program ,we can use this ServletConfig object.Servlet container creates this
ServletConfig object when instantiation event is raised on our servlet class.
ServletConfig object means,it is the object of servlet container supplied
java class that implements "javax.servlet.ServletConfig " interface.using this servletconfig bject when can get various details of our servlet program.our class(user defined class) extends HttpServlet class which is an abstract class that inturns extends GenericServlet class.
ex: public class servletdemo extends HttpServlet{//code}.As we cannot create object to HttpServlet class since abstract class we make our class extends it and use the required methods like doXxx(-,-) /service(-,-).
The beauty of HttpServlet class is, it an abstract class that contains no abstract methods(as any abstract class may or may not contain abstract method,means it can contain abstract methods also concrete methods)
for better understanding i suggest you to refer the source code of servlet-api. If you find the above explanation is not help full then please excuse me.. Thank you