On Thu, 8 Mar 2001 [EMAIL PROTECTED] wrote:

> OK this is how to get init-params working for JSP
> 
> Include this in your web.xml file
> 
> <web-app>
> <context-param>
>         <param-name>
>            foo
>         </param-name>
>         <param-value>
>            bar
>         </param-value>
> </context-param>
> </web-app>
> 
> And then in your JSP page:
> 
> String s = application.getInitParameter("foo");
[ ... ]

I'm sorry, but I must object :-).  This isn't how to get init-param's
working with JSP, so it's not a solution -- and I wouldn't even call
it a workaround, because you don't need to do a workaround.  What I
said in a previous note should work.  I constructed an example to
demonstrate it.

Here's the relevant stuff from the web.xml file (which is located in
<path-to-tomcat>/webapps/blah/WEB-INF/):

  <servlet>
    <servlet-name>testy</servlet-name>
    <jsp-file>testy.jsp</jsp-file>
    <init-param>
      <param-name>var1</param-name>
      <param-value>value1</param-value>
    </init-param>
    <init-param>
      <param-name>var2</param-name>
      <param-value>value2</param-value>
    </init-param>
  </servlet>

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

I've appended the JSP after my sig.

I used a URL of the form:

http://my.domain.com/blah/testy.jsp

The only thing I had trouble with was where the test.jsp file should
go.  I tried it in <path-to-tomcat>/webapps/blah/WEB-INF/classes/, and
it didn't work.  I put it in <path-to-tomcat>/webapps/blah/, and it
did work.  I'm not sure I fully understand why that is, but at least I
did get the init-param's working.

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



<HTML>
<HEAD>
<TITLE>Testy</TITLE>
</HEAD>
<BODY>
<%@ page
    import="java.util.*"
%>
<%!
    Enumeration names;
    String name;
%>
<P>
The value of init parameter var1 is:
<%=
    getServletConfig().getInitParameter("var1")
%>
</P>
<P>
The init parameters are:
<UL>
<%
    names = getServletConfig().getInitParameterNames();
    while (names.hasMoreElements()) {
       name = (String) names.nextElement();
%>
<LI>
<%=
       name
%>
=
<%=
       getServletConfig().getInitParameter(name)
%>
<%
    }
%>
</UL>
</P>
</BODY>
</HTML>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to