It's not a secret anymore!
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

config.getInitParameter() is null

Tijo Mathew

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
fileName = config.getInitParameter("");
in = config.getServletContext().getResourceAsStream(fileName);
catch(Exception e)
System.out.println("error from config"+e);


please guide me by rectifying the error.
Thanks in advance
Bharat Kasodariya
Ranch Hand

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

Joined: Mar 12, 2012
Posts: 16
again it is giving the same error.
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 ** . 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

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:
subject: config.getInitParameter() is null
It's not a secret anymore!