This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getServletConfig Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "getServletConfig" Watch "getServletConfig" New topic
Author

getServletConfig

Vidya Sethuraman
Ranch Hand

Joined: Sep 28, 2003
Posts: 45
Hi,

I tried the example program in HFS book page 154.
I have defined init-param values in web.xml
<init-param>
<param-name>adminEmail</param-name>
<param-value>kathy@javaranch.com</param-value>
</init-param>

<init-param>
<param-name>mainEmail</param-name>
<param-value>vidya5678@javaranch.com</param-value>
</init-param>

I am trying to print the values of mainEmail and adminEmail in my servlet class. But getting null.
Enumeration e = getServletConfig().getInitParameterNames();
while (e.hasMoreElements()) {
out.println("<br>param name = " + e.nextElement() + "<br>");
}
out.println("main email is ");
+ getServletConfig().getInitParameter("mainEmail"));
out.println("<br>");
out.println("admin email is ");
+ getServletConfig().getInitParameter("adminEmail"));

But when I deploy in Tomcat I get the following output in browser
test init params
main email is null
admin email is null

Thanks,
Vidya


Vidya <br />(SCJP 1.4)
Vidya Sethuraman
Ranch Hand

Joined: Sep 28, 2003
Posts: 45
Hi,

I tried the example program in HFS book page 154.
I have defined init-param values in web.xml
<init-param>
<param-name>adminEmail</param-name>
<param-value>kathy@javaranch.com</param-value>
</init-param>

<init-param>
<param-name>mainEmail</param-name>
<param-value>vidya5678@javaranch.com</param-value>
</init-param>

I am trying to print the values of mainEmail and adminEmail in my servlet class. But getting null.
Enumeration e = getServletConfig().getInitParameterNames();
while (e.hasMoreElements()) {
out.println("<br>param name = " + e.nextElement() + "<br>");
}
out.println("main email is " + getServletConfig().getInitParameter("mainEmail"));
out.println("<br>");
out.println("admin email is " + getServletConfig().getInitParameter("adminEmail"));

But when I deploy in Tomcat I get the following output in browser
test init params
main email is null
admin email is null

Thanks,
Vidya
Vidya Sethuraman
Ranch Hand

Joined: Sep 28, 2003
Posts: 45
Hi,

I realised the mistake I had made. I had not put the ini-param tag within the servlet tag.

Thanks,
MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getServletConfig
 
Similar Threads
Error while testing InitParameter()
Get and Post with Init Params
Head First Testing Init Paramters
getServletConfig() in pageContext() not working
getServletConfig() and getServletContext()