• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

purpose of init method

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is purpose of init method in servlet
If I don�t write init () what will happen? Will it compile?
If I write static block and do whatever init method do?will it compile?
if i write static block and init method which block will run first ()?
bye
chaitanya
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since init() is an instance method, your static block would be executed first. The servlet container is guaranteed to call init before servicing the first request.
Why are you interested in circumventing the servlet API conventions?
Bill
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
init() is mainly implemented by the developer to get the initialization parameters.
public void init(){
getServletConfig().getInitParameter("parameter1");
}
.......web.xml......
<servlet>
<servlet-name>.......
<init-param>
<param-name>parameter1</param-name>
<param-value>first</param-value>
</init-param>
</servlet>
.......................
The above can not be done using static block or anything else.
Conatiner calls init(ServletConfig) method and passes the initialization parameters by wrapping to ServletConfig object....which in turn calls
init() method implemented by developer.Here you can access the config object by getServletConfig() method.
Regards
Afroz Ahmed
SCJP(1.4)
SCWCD...on track
 
reply
    Bookmark Topic Watch Topic
  • New Topic