• 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

About init(ServletConfig)/Intialization

 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GenericServlet has one of init method as :
void init(ServletConfig config)
and also GenericServlet implements da ServletConfig interface.
Spec says " The container initializes the servlet instance by calling the init method of the Servlet interface with a
unique (per servlet declaration) object implementing the ServletConfig interface."

My questions are :
- "What is the need/use of GenericServlet implementing ServletConfig itself , as it is the responsibility of web-container to pass config-Object to init()."
( GenericServlet IS-A ServletConfig sounds weird to my ears )
- As GenericServlet implements ServletConfig , any subclass of it 'll inherit methods in interface ServletConfig too. So , suppose i subclass GenericServlet , and in some method of this subclass i call some method of ServletConfig , say i call getSevletContext() . In this case " Do GenericServlet class have some of its own implementation of getServletContext() , or does it internally calls the same method upon ServletConfig passed in init() ? "
( as reference to original ServletConfig passed in init() is stored )

------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In short, all is in the name : Generic ... The purpose is to set a simple class which allow to develop rapidly generic servlet. That's all !
Anyway, most developpers use Http version of the servlet.
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gagan Indus:
So , suppose i subclass GenericServlet , and in some method of this subclass i call some method of ServletConfig , say i call getSevletContext() . In this case " Do GenericServlet class have some of its own implementation of getServletContext() , or does it internally calls the same method upon ServletConfig passed in init() ? "
( as reference to original ServletConfig passed in init() is stored )


GenericServlet just passes on the call to the ServletConfig object that it stored.
If you get the "jakarta-servletapi-4" package that is available for download with Tomcat, you can check out the implementation of GenericServlet for yourself in the src directory.
Here's the URL for the package:
http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0/jakarta-servletap i-4.tar.gz
(there's .zip version too)


[This message has been edited by Tim Duncan (edited October 19, 2001).]
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankx Stephane and Tim !
Stephane , so was it to make servlet developers life lill 'easy' ?
I knw we all extend HttpServlet , but it IS-A GenericServlet , which further IS-A Servlet-Config , which effectively implies HttpServlet IS-A Servlet-Config . So sometimes to make life easier , we have to relax OOPs-thinga lill
Yes Tim i got da perfect ans to second q , by looking at source code . thankx
------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
reply
    Bookmark Topic Watch Topic
  • New Topic