• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in getInitParameter( String name )

 
Balasubramani Dharmalingam
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code 1 :

public void doGet( HttpServletRequest req , HttpServletResponse res )
throws IOException , ServletException {
PrintWriter out = res.getWriter();
out.print( getInitParameter( "E-mail" ) );
}

code 2:

public void doGet( HttpServletRequest req , HttpServletResponse res )
throws IOException , ServletException {
PrintWriter out = res.getWriter();
out.print( getServletConfig().getInitParameter( "E-mail" ) );
}


in code 1 i have used getInitParameter() method of Servlet class.
In code 2 i have used getInitParameter() method of ServletConfig class.
in both case i am getting the value for the parameter..

is there any difference between these two codes...?
 
AmitKumar Jain
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no difference. In both cases, the vaue of init-param for the servlet from web.xml will be retrieved
 
Anand Wadhwani
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi BalaSubramani,

Any method of ServletConfig class can directly be invoked in a GenericServlet implementation class because GenericServlet implements ServletConfig interface.

Please refer the following thread:

http://www.coderanch.com/t/169805/java-Web-Component-SCWCD/certification/Purpose-ServletConfig

The thread is remained unanswered, and may be there is no answer too. That's a redundancy in API for programmer's convenience.

Hope it helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic