Re: Frustration with getInitParameter

2001-02-12 Thread Bill Brooks

On Fri, 27 Oct 2000, Craig R. McClanahan wrote:

 Paul Hoepfner-Homme wrote:
 
  Sorry, typo in web.xml below.  I had
  servlet-paramMyServlet/servlet-param before, but it should be
  servlet-class obviously.  I have fixed it below.
 
  Finally, I'm not alone!!  I have 3.2 beta 6 as well.
  [..post elided..]
  I can access the "test1" parameter by calling
  getServletConfig().getServletContext().getInitParameter("test1").


 
 What request URI are you trying to use to access this servlet?  If you
 are trying something like:
 
 http://localhost:8080/myapp/servlet/myservlet
 
 or
 
 http://localhost:8080/myapp/servlet/MyServlet
 
 (where "/myapp" is the context path of your application), it is not
 going to work.  The reason is that "/servlet/myservlet" runs the invoker
 servlet, which indirectly loads and executes yours.  To access servlet
 initialization parameters, you will also need to add a servlet mapping
 for this servlet, and then call it.  Add this to the bottom of your
 web.xml (before the /web-app entry)
 
 servlet-mapping
 servlet-namemyservlet/servlet-name
 url-pattern/foo/*/url-pattern
 /servlet-mapping
 
 and then execute:
 
 http://localhost:8080/myapp/foo
 
 and see what happens.
 
 NOTE:  It is quite possible that some servlet containers will return
 initialization parameters for a servlet accessed via something like
 "/servlet" anyway.  That's legal, because the whole idea of an "invoker"
 servlet is not in the servlet spec, and is therefore not guaranteed to
 be portable.  Using a servlet mapping and executing your servlet that
 way, on the other hand, *is* in the spec and will work on any 2.2 or 2.3
 compliant servlet container.
 
 Craig McClanahan
 
 



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




Re: Frustration with getInitParameter

2000-10-27 Thread Craig R. McClanahan

Paul Hoepfner-Homme wrote:

 Sorry, typo in web.xml below.  I had
 servlet-paramMyServlet/servlet-param before, but it should be
 servlet-class obviously.  I have fixed it below.

 Finally, I'm not alone!!  I have 3.2 beta 6 as well.  Here is a how
 I have web.xml set up:

 web-app
 context-param
 param-nametest1/param-name
 param-valuehere1/param-value
 /context-param
 servlet
 servlet-namemyservlet/servlet-name
 servlet-classMyServlet/servlet-class
 init-param
 param-nametest2/param-name
 param-valuehere2/param-value
 /init-param
 /servlet
 /web-app

 I can access the "test1" parameter by calling
 getServletConfig().getServletContext().getInitParameter("test1").
 But I cannot access the "test2" parameter at all.  For example
 calling getServletConfig().getInitParameter("test2") returns null.

 Paul


What request URI are you trying to use to access this servlet?  If you
are trying something like:

http://localhost:8080/myapp/servlet/myservlet

or

http://localhost:8080/myapp/servlet/MyServlet

(where "/myapp" is the context path of your application), it is not
going to work.  The reason is that "/servlet/myservlet" runs the invoker
servlet, which indirectly loads and executes yours.  To access servlet
initialization parameters, you will also need to add a servlet mapping
for this servlet, and then call it.  Add this to the bottom of your
web.xml (before the /web-app entry)

servlet-mapping
servlet-namemyservlet/servlet-name
url-pattern/foo/*/url-pattern
/servlet-mapping

and then execute:

http://localhost:8080/myapp/foo

and see what happens.

NOTE:  It is quite possible that some servlet containers will return
initialization parameters for a servlet accessed via something like
"/servlet" anyway.  That's legal, because the whole idea of an "invoker"
servlet is not in the servlet spec, and is therefore not guaranteed to
be portable.  Using a servlet mapping and executing your servlet that
way, on the other hand, *is* in the spec and will work on any 2.2 or 2.3
compliant servlet container.

Craig McClanahan





RE: Frustration with getInitParameter

2000-10-26 Thread Kitching Simon

Hi Paul,

When you say "the servlet's getInitParameter("test")" what *exactly* do you
mean?

Do you mean that your servlet's init method is like:

  public void init(ServletConfig config) throws ServletException {
super.init(config);

  Object o = config.getInitParameter("test");
  
 
If so, then all I can say is it works for me.

According to the docs, you should also be able
to do this inside the service method:

Object o = this.getServletConfig().getInitParameter("test");

I haven't tried this, though..

Regards,

Simon

 -Original Message-
 From: Paul Hoepfner-Homme [SMTP:[EMAIL PROTECTED]]
 Sent: Thursday, October 26, 2000 4:26 PM
 To:   [EMAIL PROTECTED]
 Subject:  Frustration with getInitParameter
 
 Tomcat 3.2 beta 6.  I have a servlet in the ROOT context.  The web.xml
 file in webapps/ROOT/WEB-INF has this entry: 
 servlet 
 servlet-name.../servlet-name 
 servlet-classMyServlet/servlet-class 
 init-param 
 param-nametest/param-name 
 param-valuehere/param-value 
 /init-param 
 ... 
 /servlet 
 
 From MyServlet I use the servlet's getInitParameter("test") method and it
 returns null.  When I try to iterate through the parameter names, there
 are none to iterate through. 
 
 What am I doing wrong?? 
 
 Thanks 
 --
 Paul Hoepfner-Homme
 [EMAIL PROTECTED]
 
 OVEN Digital |  http://www.oven.com/
  



Re: Frustration with getInitParameter

2000-10-26 Thread Paul Hoepfner-Homme


Paul Hoepfner-Homme wrote:
Yes, this is what I am trying to do. Maybe
I'll try overriding the init() method of my servlet and try to call it
up from there, but as you say, the docs say I should be able to do it from
within a service method, so I shouldn't have to do this.
No such luck. Even when I override init() and in there use getInitParameter
from my ServletConfig, there are still zero init parameters, yet Ihave
now defined six in web.xml for this servlet context. And they are
init-param>s inside the servlet> definition, not context-param>s
as some people have mistakenly tried and then complained on the mailing
list that they couldn't access the values using getInitParameter().
Please help!

> -Original Message-
> From: Paul Hoepfner-Homme [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, October 26, 2000 4:26 PM
> To: [EMAIL PROTECTED]
> Subject: Frustration with getInitParameter
>
> Tomcat 3.2 beta 6. I have a servlet in the ROOT context.
The web.xml
> file in webapps/ROOT/WEB-INF has this entry:
> servlet>
> servlet-name>.../servlet-name>
> servlet-class>MyServlet/servlet-class>
> init-param>
> param-name>test/param-name>
> param-value>here/param-value>
> /init-param>
> ...
> /servlet>
>
> From MyServlet I use the servlet's getInitParameter("test") method
and it
> returns null. When I try to iterate through the parameter names,
there
> are none to iterate through.
>
> What am I doing wrong??
>
> Thanks
> --
> Paul Hoepfner-Homme
> [EMAIL PROTECTED]
>
> OVEN Digital | http://www.oven.com/>
>

--
Paul Hoepfner-Homme
[EMAIL PROTECTED]

OVEN Digital | http://www.oven.com/


--
Paul Hoepfner-Homme
[EMAIL PROTECTED]

OVEN Digital | http://www.oven.com/