• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets and ServletConfig problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried working with Servlets ServletConfig. As I understood the
GenericServlet
gets the parameters automatically and using getServletConfig() brings
the config.
Now I have a servlet that extends from HttpServlet.
in it I have the init() method and in this method I call the
getServletConfig() but I get
a ServletConfig instance with no parameters !!!
What am I doing wrong ?

The parameters are set in the web.xml file descriptor.

<context-param>
<param-name>telephone</param-name>
<param-value>1234</param-value>
</context-param>


Now the problem with the getInitParameter() is that it doesn't bring the value
of "telephone" for example.
Furthermore the :
servletConfig.getInitParameterNames().hasMoreElements()
retruns false !!
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a forum exclusive for Servlets. I feel that this question should have been asked there.

You are setting the values to <context-param> tag. Which means you can access there variables by getting a handle on your Servlet Context and calling getInitParameter("telephone").

This is what you should have in your servlet mapping to retrieve the parameters through your getServletConfig().getInitParameter("telephone")
<init-param>
<param-name>telephone</param-name>
<param-value>1234</param-value>
</init-param>

Hope that helps
 
itamar lev
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes it helped.
Thank you very much.

Itamar
reply
    Bookmark Topic Watch Topic
  • New Topic