File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt in getInitParameter( String name ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt in getInitParameter( String name )" Watch "Doubt in getInitParameter( String name )" New topic
Author

Doubt in getInitParameter( String name )

Balasubramani Dharmalingam
Ranch Hand

Joined: Dec 06, 2004
Posts: 116
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...?


Balasubramani SD,<br />SCJP 1.4,SCWCD 1.4,SCJP 5.0<br /><a href="http://sd.balasubramani.googlepages.com" target="_blank" rel="nofollow">www.sd.balasubramani.googlepages.com</a>
AmitKumar Jain
Ranch Hand

Joined: Jun 13, 2005
Posts: 95
There's no difference. In both cases, the vaue of init-param for the servlet from web.xml will be retrieved


SCJP 1.4 : 91%
SCWCD 1.4 : 95%
SCBCD 1.3 : 95%
SCJP 6 Upgrade : 95%
Next SCBCD 1.5
Man is not finished when he is defeated. He is finished when he quits.
Anand Wadhwani
Ranch Hand

Joined: Mar 21, 2005
Posts: 151
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.


SCWCD 1.4<br />---------------------<br />Ability is what you're capable of. <br />Motivation determines what you do. <br />Attitude determines how well you do it.<br />---------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in getInitParameter( String name )
 
Similar Threads
servlet
compatibility of date format
Using sessions for authentication
doGet() method error
core java communicates with servlet or jsp?