Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why call getServletConfig()?

 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In page 150 of the HFSJ book, we have this code:

out.println(getServletConfig().getInitParameter("adminEmail"));

Why do we need to call getServletConfig()? The servlet itself implements the ServletConfig interface, so can't we simply do:

out.println(getInitParameter("adminEmail"));
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure you can do it the second way. It is just a convience method inherited from GenericServlet that does the exact same thing.
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. In that case, why bother with the redundant getServletConfig() call?
 
Adam Czysciak
Ranch Hand
Posts: 90
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Edmund Yong:
Thanks. In that case, why bother with the redundant getServletConfig() call?


I think it's because this chapter was about to teach what ServletConfig is and what can it offer to you, the servlet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic