On Fri, 27 Apr 2001, Brendan McKenna wrote:

> Hi,
>
>       Newbie question here.  I've looked in the FAQ (and, for that
> matter, in the Servlet API specs) and am having trouble figuring out
> how to access parameters specified via <context-param> in my JSP
> pages.  Am trying to use <%= application.getInitParameter(<name>)
> %>, but Jasper complains that the parameter has no value.  This
> -seemed- to me to be the way to do it.  I've also tried using
> config.getInitParameter(), to no avail.
>
>       I am certain that the matching parameters have values in the
> web.xml file, and that the names that I am using match the names
> specified.  So I figure that I must be doing something else wrong...

Probably :-).

It may be that in order for a servlet or a jsp to be able to access
context-param's, it (i.e. the servlet or jsp) must be defined in the
context's web.xml file, i.e. via a servlet tag.  When defining a
servlet, you specify the servlet-class, when defining a jsp, you
specify the jsp-file.  Have you done that for your jsp?

Also, when you define a servlet or jsp, it must be called via the
servlet-name you specify for it.  But you can add servlet-mapping's to
specify alternate names to call it by.  And the url-pattern in a
mapping can be of the form something.jsp (so you can still call a jsp
by a jsp-looking name).

Let me illustrate with an example.  Suppose the context/application is
called myapp.  Let's assume the context-param's are defined correctly
in the web.xml file.  Then you have a jsp called foo.jsp that you want
to be part of myapp, and be able to access those context-param's.
You'd do something like:

   <servlet>
     <servlet-name>foo</servlet-name>
     <jsp-file>foo.jsp</jsp-file>
   </servlet>

   <servlet-mapping>
     <servlet-name>foo</servlet-name>
     <url-pattern>foo.jsp</url-pattern>
   </servlet-mapping>

I believe the file foo.jsp should go in <path-to-tomcat>/webapps/myapp/.

Then you should be able to access the context-param's in foo.jsp
(using either of the application or config predefined variables).

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

Reply via email to