• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getServletConfig

 
Vidya Sethuraman
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Thanks,
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic