• Post Reply Bookmark Topic Watch Topic
  • New Topic

using getInitParameter() directly vs. config.getInitParameter()  RSS feed

 
Arvind Mahendra
Ranch Hand
Posts: 1162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would I write :

ServletConfig config = getServletConfig();
String URL = config.getInitParameter("URL");


when I can just write:
String URL = getInitParameter("URL");


What are some of the benefits? of doing it in either way?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't say, but I assume that you are doing this from a servlet.

In the first case, you are calling the method on the ServletConfig instance, for the second, a method on the servlet instance (declared in GenericServlet, to be exact).

Refer to the API javadoc for these two methods and you will see how they differ (or don't).
[ September 04, 2007: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!