A.K.A.F Illayapparachchi

Greenhorn
+ Follow
since Oct 19, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by A.K.A.F Illayapparachchi

To get servlet init parameters, In head first book , I saw that it use the following code :

getServletConfig().getInitParameter("Name of The parameter");

add it also saying that getServletConfig() passes the Reference of the ServletConfig.

But every Servlet extends form the HttpServlet . And It extends GenericServlet(it is also the place where getServletConfig() is defines). This GenericServlet implements the ServletConfig. If Generally Speaking, GenericServlet is a ServletConfig. There for Every Servlet is a ServletConfig.

All methods in ServletConfig is implemented in the GenericServlet.

Therefor without calling getServletConfig() and getting it's reference. We can directly calls the getInitparameter(), getServletConfig(), getServletName() & getInitParameterNames().


My Problem is this

out.println(getServletConfig().getInitParameter("value name"));


out.println(getInitParameter("value name"));


both of the lines compiles properly.
both of the lines prints same output.(In the Web applications that i have made)
but second one is easy to use.


Is there any difference in this? or Is it a convention?
12 years ago