This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

getServletConfig

 
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,
 
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!