Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the use of servlet config object??

 
senthil sen
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the use of the servlet object??and where can it be used often...
 
Nikki Aniban
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! ServletConfig is an interface that has defined methods where you can get the initialization parameters that you specified for a particular servlet in your web.xml.
For example your web.xml look like this:
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
<init-param>
<param-name>name</param-name>
<param-value>diego</param-value>
</init-param>
</servlet>
then in your servlet you can use this code to get the value of "diego":
getServletConfig().getInitParameter("name");
Just check the API to see the other methods that are defined. But wait, here's the clincher, the ServletConfig is implemented by GenericServlet which is in turn, extended by HttpServlet. So, in the ideal world, you don't have to create an instance of ServletConfig just to get initialization parameters because you can directly access it from your servlet.
Bottomline is: ServletConfig is not used often.
Hope this answers your question.
 
Jagdeep Singh
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletConfig is a abstract interface and this object is used by a servlet CONTAINER to pass information to a servlet(s)during initialization.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic