• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

config.getInitParameter() is null

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am facing problem with config.getInitParameter() which returns null everytime.
i am attaching my servlet code and web.xml
servlet code

String fileName=null;
InputStream in=null;
public void init(ServletConfig config) throws ServletException
{
try
{
fileName = config.getInitParameter("consumer.properties");
System.out.println("filename"+fileName);
in = config.getServletContext().getResourceAsStream(fileName);
System.out.println("filename"+in);
}
catch(Exception e)
{
System.out.println("error from config"+e);
}
}

web.xml
<servlet>
<servlet-name>ProviderServlet</servlet-name>
<servlet-class>all.providers.ProviderServlet</servlet-class>
<init-param>
<param-name>consumer.properties</param-name>
<param-value>E:/workspace/allproviders/WebContent/WEB-INF/lib/consumer.properties</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ProviderServlet</servlet-name>
<url-pattern>/providers</url-pattern>
</servlet-mapping>

please guide me by rectifying the error.
Thanks in advance
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"oauth_consumer.properties" param is missing in your web.xml
 
Tijo Mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
again it is giving the same error.
filenamenull
filenamenull
please guide me asap
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
debugging hint:
try calling config.getInitParameterNames() and see you get param name *consumer.properties* . if not my guess is that your web.xml is not properly deployed.
 
Ranch Hand
Posts: 45
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also is the piece of code inside all.providers.ProviderServlet servlet class or a class method called from this servlet ? If it is under some other servlet the servlet config parameter will not be available.
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are overridding init(ServletConfig) method here. while overridding this method you should first call super.init(config). without that config won't be available to your webapp. a much better thing would be to override the public void init() method and provide your initialization code there.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic