Why can not we call servlet constructor instead of init method to initialize the config parameters?

前端 未结 2 1011
灰色年华
灰色年华 2021-01-02 02:45

I like to know why dont we call servlet constructor instead of init method to initialize the config parameters.

THanks

2条回答
  •  暖寄归人
    2021-01-02 03:11

    In general we can use constructor to perform initialization activities but in old version of java(JDK1.0v), constructor can not accept dynamically generated class name as argument. To perform initialization of a servlet compulsory we should provide ServletConfig object as an argument whose class name dynamically generated by web container , as constructor can’t accept the dynamically generated class names hence, sun people ignored the constructor concept and introduced a specific method init(-) to perform initialization activities which can take dynamically generated class name as an argument.

提交回复
热议问题