tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kitching Simon <>
Subject reading web.cml config parameters from jsp pages
Date Mon, 21 Aug 2000 09:21:25 GMT
Hi all,

I have a *jsp* page that needs some configuration parameters (JDBC connect
strings, etc).
I would like to set these in the web.xml file, but just can't get it

There appears to be two ways to set parameters: 
(a) at the "application" level (ie they are fetched from the ServletContext
object), and
(b) at the page/servlet level (ie they are fetched from the ServletConfig

I can get both running with servlets, and (a) running with jsp pages, but
not (b). I would *really* appreciate help...

The <servlet> tag in web.xml can take a set of <init-param> tags that get
stored in the
ServletContext object passed to the servlet. I can get this working fine for

The servlet tag can also take a <jsp-file>name</jsp-file>, where the
contents are
described as "the full path to the jsp file". I'm not sure if this means
absolute path
from root (/home/skitchin/.....) or relative to the ServletContext base
directory, but
it doesn't seem to work either way.

My best attempt at the web.xml file is:

<!-- per-page config parameters for jsp pages -->

The jsp-file code I have is:    

The parameters available from the ServletConfig object are:
  Enumeration e = config.getInitParameterNames();
  while (e.hasMoreElements())
    String name = (String) e.nextElement();
    String value = config.getInitParameter(name);
    out.println("name=[" + name + "] value=[" + value + "]");

I can see two possible causes for the above not working:
(1) the <jsp-file> attribute actually wants a path to the .class file (in
the tomcat work directory).
This seems impossible to me, as tomcat generates its own name for this file.
(2) that the default ".jsp" --> "jsp-handling-servlet" mapping in the
*default* web.xml in the
tomcat/conf directory is somehow interfering with passing params to the jsp

I'm not sure if either of the above is the problem, or, if it is, quite what
to do about it :-)

Many thanks in advance,

Simon Kitching

NB: The following is the code/config I can use to get "application" level
params passed.
I attach it for interest only.

However, I don't want to use the "application" level params because:
(a) the parameters are actually only needed by one page; making them
"global" is a little messy
(b) more importantly, my IDE (Oracle JDeveloper 3.1) doesn't appear to
support the
"getInitParameter" method on the application (ServletContext) object. To
compile this, I need to
compile at the command level, which isn't very convenient (perhaps this is a
jsp1.1 feature??)

In web.xml:

    <!-- application-level config parameters accessable by beans & jsp pages
      <param-value>fred woz here</param-value>

In jsp page:

The parameters available from the application object are:
  Enumeration e = application.getInitParameterNames();
  while (e.hasMoreElements())
    String name = (String) e.nextElement();
    String value = application.getInitParameter(name);
    out.println("name=[" + name + "] value=[" + value + "]");

View raw message