File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes config.getInitParameter() is null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "config.getInitParameter() is null" Watch "config.getInitParameter() is null" New topic
Author

config.getInitParameter() is null

Tijo Mathew
Greenhorn

Joined: Mar 12, 2012
Posts: 16
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

Joined: Aug 19, 2011
Posts: 36
"oauth_consumer.properties" param is missing in your web.xml
Tijo Mathew
Greenhorn

Joined: Mar 12, 2012
Posts: 16
again it is giving the same error.
filenamenull
filenamenull
please guide me asap
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Mar 14, 2010
Posts: 45

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.


SCJP 1.6,Preparing (Tryin to prepare) for scwcd
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: config.getInitParameter() is null