Re: Servlet Init method
Chris Pratt <[email protected]> Thu, 1 Sep 2005 09:02:58 -0700
| Newsgroups | gmane.comp.java.sun.servlet |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_10084_13767881.1125590578902 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Actually, what I remember from the early days of Servlets, it is because th= e=20 Servlet API is interface based, and you can't specify constructors in a Jav= a=20 interface. The developers decided to use a method that they can specify in= =20 the interface contract. (*Chris*) On 9/1/05, Nic Ferrier <[email protected]> wrote: >=20 > Sreenath N <[email protected]> writes: >=20 > > Reason might be init() method needs a ServletConfig object to be passed > > which is used for retreving the init-params and the container can't=20 > expect > > the user to write a constructor which takes the ServletConfig object > > . >=20 > No. Clearly this is wrong, type checking can enforce that requirement: >=20 > public abstract class Servlet > { > public Servlet(ServletConfig sc) > { > // do some stuff > } >=20 >=20 > // do some stuff > } >=20 >=20 > The reason a servlet has an init method, as opposed to a constructor > is that a constructed instance of a servlet can be deployed and > undeployed from a container several times during it's lifetime. >=20 >=20 > Nic Ferrier > http://www.tapsellferrier.co.uk >=20 >=20 > _________________________________________________________________________= __ > To unsubscribe, send email to [email protected] and include in the=20 > body > of the message "signoff SERVLET-INTEREST". >=20 > Archives: http://archives.java.sun.com/archives/servlet-interest.html > Resources: http://java.sun.com/products/servlet/external-resources.html > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > ___________________________________________________________________________ To unsubscribe, send email to [email protected] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ------=_Part_10084_13767881.1125590578902 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Actually, what I remember from the early days of Servlets, it is because the Servlet API is interface based, and you can't specify constructors in a Java interface. The developers decided to use a method that they can specify in the interface contract.<br> (*Chris*)<br><br><div><span class=3D"gmail_quote">On 9/1/05, <b clas= s=3D"gmail_sendername">Nic Ferrier</b> <<a href=3D"mailto:nferrier@tapse= llferrier.co.uk">[email protected]</a>> wrote:</span><blockq= uote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204, 20= 4); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Sreenath N <<a href=3D"mailto:[email protected]">[email protected]= </a>> writes:<br><br>> Reason might be init() method needs a ServletC= onfig object to be passed<br>> which is used for retreving the init-para= ms and the container can't expect <br>> the user to write a constructor which takes the ServletConfig obje= ct<br>> .<br><br>No. Clearly this is wrong, type checking can enforce th= at requirement:<br><br> public abstract class Servlet<br> = {<br> public Servlet(ServletConf= ig sc) <br> {<br>  = ; // do some stuff<br> = }<br><br><br> // do some s= tuff<br> }<br><br><br>The reason a servlet has an init method, = as opposed to a constructor<br>is that a constructed instance of a servlet = can be deployed and <br>undeployed from a container several times during it's lifetime.<br><br>= <br>Nic Ferrier<br><a href=3D"http://www.tapsellferrier.co.uk">http://www.t= apsellferrier.co.uk</a><br><br>____________________________________________= _______________________________ <br>To unsubscribe, send email to <a href=3D"mailto:[email protected]">= [email protected]</a> and include in the body<br>of the message "s= ignoff SERVLET-INTEREST".<br><br>Archives: <a href=3D"http://archives.= java.sun.com/archives/servlet-interest.html"> http://archives.java.sun.com/archives/servlet-interest.html</a><br>Resource= s: <a href=3D"http://java.sun.com/products/servlet/external-resources.html"= >http://java.sun.com/products/servlet/external-resources.html</a><br>LISTSE= RV Help:=20 <a href=3D"http://www.lsoft.com/manuals/user/user.html">http://www.lsoft.co= m/manuals/user/user.html</a><br></blockquote></div><br> ___________________________________________________________________________ To unsubscribe, send email to [email protected] and include in the body of the message "signoff SERVLET-INTEREST". <p> Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html <p> ------=_Part_10084_13767881.1125590578902--