wood burning stoves 2.0*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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