• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

config.getInitParameter

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm trying to access an intialisation parameter in a jsp file.
My web.xml file has the following entry
<servlet>
<servlet-name>Jsp1</servlet-name>
<display-name>Jsp1</display-name>
<jsp-file>/Jsp1.jsp</jsp-file>
<init-param>
<param-name>myInitial</param-name>
<param-value>Y</param-value>
</init-param>
</servlet>
Using config.getInitParameter("myInitial")in the JSP always returns null!!!
Has anyone else had these problems and sorted it out.
TIA Graham
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Cheers
 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
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.
 
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Mark
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,
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
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Robert
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.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
getServletContext().getInitParameter("name");
-Pat
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic