Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

config.getInitParameter() is null

 
Tijo Mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Bharat Kasodariya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
again it is giving the same error.
filenamenull
filenamenull
please guide me asap
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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.
 
Harsha Ka
Ranch Hand
Posts: 45
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic