• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in getInitParameter( String name )

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...?
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

https://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.
reply
    Bookmark Topic Watch Topic
  • New Topic