File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes config.getInitParameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "config.getInitParameter" Watch "config.getInitParameter" New topic


Graham Mead
Ranch Hand

Joined: Sep 28, 2001
Posts: 57
Hi I'm trying to access an intialisation parameter in a jsp file.
My web.xml file has the following entry
Using config.getInitParameter("myInitial")in the JSP always returns null!!!
Has anyone else had these problems and sorted it out.
TIA Graham
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You might be confusing servlet init params with context init params.
Call getInitParameter on the servlet itself (i.e. remove the "config.") and this should fix your problem.
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
let me disagree with the last post. to use the context parameters you set the <context-param>
tag, and not <init-param>.
i guess you get your init parametes == null because you have to call your servlets with path which includes your <servlet-name> and not the direct path.

Asher Tarnopolski
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
I know this was a while ago. but I got the answer for you. The problem was after you set up your servlet context for your JSP, you need to set up a servlet mapping so the web server can map the servlet context to your jsp! Like this:
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Hi Graham
I suspect you may be calling the JSP file directly, instead of using the deployment decriptor configuration.
That is, if you call your JSP file with:

then you will definitely get a null return from config.getInitParameter("myInitial").
However, if you invoke your JSP file with:

then you should get your desired result.
Hope this helps
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Yes, but even though he set Servlet-Name, if he has no servlet mapping, then you're idea won't work.
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
It wasn't just an idea. I ran Graham's code that he supplied in his post and it worked. Servlet mapping is definitely not a pre-req to locating a JSP page.
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
You definitely don't have to use servlet mappings if you set your init-param's in your web.xml like this:

then to call it from a jsp you just use:
I agree. Here's the link:
subject: config.getInitParameter
jQuery in Action, 3rd edition