Re: config.getInitParameter() still returning null

2001-03-08 Thread Bo Xu

[EMAIL PROTECTED] wrote:

 The config.getInitParameter() called from within a JSP page is
 returning null. After changing the web.xml file numerous times and
 trying all the suggestions from java.sun.com and the tomcat archives I
 still cannot resolve this problem.
 Does anyone know why we can't access the init parameters?
 thanks in advance

 Here is what my web.xml file looks like (does not work):

 web-app
 servlet
 servlet-name
Error
 /servlet-name
 servlet-class
 org.apache.jasper.runtime.JspServlet
 /servlet-class
 init-param
 param-namedebug/param-name
 param-valuetrue/param-value
 /init-param
 /servlet
 /web-app

 and my JSP code:
 %
 String s = config.getInitParameter("debug");
 if (s == null) {
 out.println("Init param must be null!");
 }
 else{
 out.println("Init param is "+s);
 }
 %

Hi :-)  I didn't ever use jsp to get init parameters, but I guess
the reasons is: in your WEB_INF/web.xml, you only define
a servlet definition with some init parameters, but you didn't
define a servlet-mapping; and/so I guess you invoked your
servlet without url-pattern(servlet-mapping name) - I guess
you use: http://localhost:8080/myapp/servlet/Myservlet ,
so if you use Servlet, the following will return null:
 - config.getInitParameter(...)
-  this.getInitParameter(...)


I suggest you:
-  in WEB_INF/web.xml, when you define a servlet definition
   with some init parameters, At the same time define a
   servlet-mapping
-  then use url-pattern to invoke your Servlet:
   http://localhost:8080/myapp/XXX   (XXX is url-pattern)
- if you don't want to define a servlet-definition and servlet-mapping
  Pair in WEB-INF/web.xml, you also can define init parameters
  in servlet context definition in conf/server.xml, and get them in
  your servlet with the following way:
  this.getServletContext().getInitParameter(...)



Bo
Mar.08, 2001



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




Re: config.getInitParameter() still returning null

2001-03-08 Thread Milt Epstein

On Thu, 8 Mar 2001, Bo Xu wrote:

 [EMAIL PROTECTED] wrote:
 
  The config.getInitParameter() called from within a JSP page is
  returning null. After changing the web.xml file numerous times and
  trying all the suggestions from java.sun.com and the tomcat archives I
  still cannot resolve this problem.
  Does anyone know why we can't access the init parameters?
  thanks in advance
 
  Here is what my web.xml file looks like (does not work):
 
  web-app
  servlet
  servlet-name
 Error
  /servlet-name
  servlet-class
  org.apache.jasper.runtime.JspServlet
  /servlet-class
  init-param
  param-namedebug/param-name
  param-valuetrue/param-value
  /init-param
  /servlet
  /web-app
 
  and my JSP code:
  %
  String s = config.getInitParameter("debug");
  if (s == null) {
  out.println("Init param must be null!");
  }
  else{
  out.println("Init param is "+s);
  }
  %
 
 Hi :-)  I didn't ever use jsp to get init parameters, but I guess
 the reasons is: in your WEB_INF/web.xml, you only define
 a servlet definition with some init parameters, but you didn't
 define a servlet-mapping; and/so I guess you invoked your
 servlet without url-pattern(servlet-mapping name) - I guess
 you use: http://localhost:8080/myapp/servlet/Myservlet ,
 so if you use Servlet, the following will return null:
  - config.getInitParameter(...)
 -  this.getInitParameter(...)
[ ... ]

I could be wrong, but I don't believe you have to define
servlet-mapping's to get init-param's to work, just having defined the
servlet is sufficient.  However, in the URL, you do need to use the
specific servlet-name you used in the servlet definition.  (That's
because you can define the same servlet class multiple times, with
different servlet-name's and different init-param's.)

So, according to the above web.xml, the URL that should be used is:

http://your.domain.com/yourwebappname/servlet/Error

(No, I haven't tested this.)

However, I just noticed that the original poster said that this is all
happening in a JSP ("JSP page" is redundant :-) -- that throws a
monkey wrench into the situation, and I'm not sure how it changes
things.  For example, I don't know how to set up init-param's in a
JSP.  Also, upon re-reading the above servlet definition, I'm not sure
that's the right way to set up a JSP -- i.e. putting
org.apache.jasper.runtime.JspServlet as the servlet-class (I assume
that's the tomcat/jasper servlet that handles JSP's).  I think you
want to name your JSP something.jsp, and just tell tomcat somewhere
that it's a JSP.  But again, I'm not sure how you'd set up
init-param's for it (maybe you do have to fallback on the suggestion
to use context init-param's, instead of servlet init-param's).

Well, I think I may have just raised more confusion, but perhaps this
will lead to some helpful discussion/ideas, and/or someone will post
clearing things up.

...

Hold on.  I decided to do a google newsgroup search on this, to see if
I can get more definite information, and looks like I found the
answers.  Check out the following posts:

http://groups.google.com/groups?q=init-param+jsphl=enlr=safe=offrnum=1seld=964886773ic=1
http://groups.google.com/groups?hl=enlr=safe=offth=9eb4e0cd3b0f1fb6rnum=9seld=958627636ic=1

Actually, I don't know if these URLs will work outside the context of
my search -- if not, go to the google advanced newsgroups search page
at:

http://groups.google.com/advanced_group_search

and enter "init-param jsp" in the "with all of the words" box (without
the quotes) and "hanna" in the "Author" box (again, without the
quotes).

Basically, it looks like a servlet definition can specify *either*
servlet-class or a jsp-file (those are the actual names of the tags
used in web.xml).  Note the warnings about what form of URL to use
when you set things up this way, though.

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


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




Re: config.getInitParameter() still returning null

2001-03-08 Thread Bo Xu

Milt Epstein wrote:

 [ ... ]

 I could be wrong, but I don't believe you have to define
 servlet-mapping's to get init-param's to work, just having defined the
 servlet is sufficient.  However, in the URL, you do need to use the
 specific servlet-name you used in the servlet definition.  (That's
 because you can define the same servlet class multiple times, with
 different servlet-name's and different init-param's.)

 So, according to the above web.xml, the URL that should be used is:

 http://your.domain.com/yourwebappname/servlet/Error
 [...]

thanks for your email :-)  and now I find mistake in my last email,
the following is my new understanding about Servlet(not JSP) with
jakarta-tomcat-4.0-b1 :

0  if we don't define any "named" servlet definition
in webapps/myapp/WEB-INF/web.xml, then we can invoke
MyServlet with the following  way:
http://localhost:8080/myapp/servlet/MyServlet
it will invoke the "default/non-named" servlet definition

1  if we define the following in webapps/myapp/WEB-INF/web.xml:
 ...
 servlet-nameMyServlet_sn /servlet-name
 ...
then we Also can invoke this servlet definition with this servlet-name:
http://localhost:8080/myapp/servlet/MyServlet_sn

2 if we also define a servlet-mapping:
servlet-mapping
 servlet-nameMyServlet_sn /servlet-name
url-pattern /MyServlet_up/url-pattern
/servlet-mapping
then we Also can invoke this servlet definition with this url-pattern:
http://localhost:8080/myapp/MyServlet_up

and 1 and 2 will invoke the same "named" servlet definition whose
name is MyServlet_sn.

3  from a email in "List.this" ^_^ ,  I find:
if we directly use "MyServlet" as the servlet-name, and we invoke
with the following way:
http://localhost:8080/myapp/servlet/MyServlet
   we will goto that "named" servlet definition whose name is
   "MyServlet"- we will Not goto that "default/non-named"
   servlet definition.

hope the above is right, otherwise I need to correct my
"experience notebook" Again :-)  or I need to use a pencial
instead of a pen?  :-)


Bo
Mar.08, 2001



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




Re: config.getInitParameter() still returning null

2001-03-08 Thread Michael . Murphy

Just to clear up what i'm trying to do:
not having any problems getting init parameters using servlets, the following code in web.xml will achieve that:

servlet
servlet-nameMyServlet/servlet-name
servlet-classMyServlet/servlet-class
init-param
param-namedebug/param-name
param-valuetrue/param-value
/init-param
/servlet

The problem is accessing init-params exclusively in JSPs without any servlets at all. In theory this should be possible as a JSP is a servlet but it's proving very difficult to do this.

Right now i'm working on a background servlet for the JSP to make these init-params possible. I'll post solution when it's done.






Bo Xu [EMAIL PROTECTED]
03/08/01 10:09 AM
Please respond to tomcat-user


To:[EMAIL PROTECTED]
cc:
Subject:Re: config.getInitParameter() still returning null


Milt Epstein wrote:

 [ ... ]

 I could be wrong, but I don't believe you have to define
 servlet-mapping's to get init-param's to work, just having defined the
 servlet is sufficient. However, in the URL, you do need to use the
 specific servlet-name you used in the servlet definition. (That's
 because you can define the same servlet class multiple times, with
 different servlet-name's and different init-param's.)

 So, according to the above web.xml, the URL that should be used is:

 http://your.domain.com/yourwebappname/servlet/Error
 [...]

thanks for your email :-) and now I find mistake in my last email,
the following is my new understanding about Servlet(not JSP) with
jakarta-tomcat-4.0-b1 :

0 if we don't define any named servlet definition
  in webapps/myapp/WEB-INF/web.xml, then we can invoke
  MyServlet with the following way:
  http://localhost:8080/myapp/servlet/MyServlet
  it will invoke the default/non-named servlet definition

1 if we define the following in webapps/myapp/WEB-INF/web.xml:
   ...
   servlet-nameMyServlet_sn /servlet-name
   ...
  then we Also can invoke this servlet definition with this servlet-name:
  http://localhost:8080/myapp/servlet/MyServlet_sn

2 if we also define a servlet-mapping:
  servlet-mapping
   servlet-nameMyServlet_sn /servlet-name
url-pattern /MyServlet_up/url-pattern
  /servlet-mapping
  then we Also can invoke this servlet definition with this url-pattern:
  http://localhost:8080/myapp/MyServlet_up

  and 1 and 2 will invoke the same named servlet definition whose
  name is MyServlet_sn.

3 from a email in List.this ^_^ , I find:
  if we directly use MyServlet as the servlet-name, and we invoke
  with the following way:
  http://localhost:8080/myapp/servlet/MyServlet
  we will goto that named servlet definition whose name is
  MyServlet- we will Not goto that default/non-named
  servlet definition.

hope the above is right, otherwise I need to correct my
experience notebook Again :-) or I need to use a pencial
instead of a pen? :-)


Bo
Mar.08, 2001



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





solved-Re: config.getInitParameter() still returning null

2001-03-08 Thread Michael . Murphy

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);








Milt Epstein [EMAIL PROTECTED]
03/08/01 08:00 AM
Please respond to tomcat-user


To:[EMAIL PROTECTED]
cc:
Subject:Re: config.getInitParameter() still returning null


On Thu, 8 Mar 2001, Bo Xu wrote:

 [EMAIL PROTECTED] wrote:
 
  The config.getInitParameter() called from within a JSP page is
  returning null. After changing the web.xml file numerous times and
  trying all the suggestions from java.sun.com and the tomcat archives I
  still cannot resolve this problem.
  Does anyone know why we can't access the init parameters?
  thanks in advance
 
  Here is what my web.xml file looks like (does not work):
 
  web-app
servlet
  servlet-name
   Error
  /servlet-name
  servlet-class
org.apache.jasper.runtime.JspServlet
  /servlet-class
  init-param
param-namedebug/param-name
param-valuetrue/param-value
  /init-param
/servlet
  /web-app
 
  and my JSP code:
  %
  String s = config.getInitParameter(debug);
  if (s == null) {
  out.println(Init param must be null!);
  }
  else{
  out.println(Init param is +s);
  }
  %
 
 Hi :-) I didn't ever use jsp to get init parameters, but I guess
 the reasons is: in your WEB_INF/web.xml, you only define
 a servlet definition with some init parameters, but you didn't
 define a servlet-mapping; and/so I guess you invoked your
 servlet without url-pattern(servlet-mapping name) - I guess
 you use: http://localhost:8080/myapp/servlet/Myservlet ,
 so if you use Servlet, the following will return null:
 - config.getInitParameter(...)
 - this.getInitParameter(...)
[ ... ]

I could be wrong, but I don't believe you have to define
servlet-mapping's to get init-param's to work, just having defined the
servlet is sufficient. However, in the URL, you do need to use the
specific servlet-name you used in the servlet definition. (That's
because you can define the same servlet class multiple times, with
different servlet-name's and different init-param's.)

So, according to the above web.xml, the URL that should be used is:

http://your.domain.com/yourwebappname/servlet/Error

(No, I haven't tested this.)

However, I just noticed that the original poster said that this is all
happening in a JSP (JSP page is redundant :-) -- that throws a
monkey wrench into the situation, and I'm not sure how it changes
things. For example, I don't know how to set up init-param's in a
JSP. Also, upon re-reading the above servlet definition, I'm not sure
that's the right way to set up a JSP -- i.e. putting
org.apache.jasper.runtime.JspServlet as the servlet-class (I assume
that's the tomcat/jasper servlet that handles JSP's). I think you
want to name your JSP something.jsp, and just tell tomcat somewhere
that it's a JSP. But again, I'm not sure how you'd set up
init-param's for it (maybe you do have to fallback on the suggestion
to use context init-param's, instead of servlet init-param's).

Well, I think I may have just raised more confusion, but perhaps this
will lead to some helpful discussion/ideas, and/or someone will post
clearing things up.

...

Hold on. I decided to do a google newsgroup search on this, to see if
I can get more definite information, and looks like I found the
answers. Check out the following posts:

http://groups.google.com/groups?q=init-param+jsphl=enlr=safe=offrnum=1seld=964886773ic=1
http://groups.google.com/groups?hl=enlr=safe=offth=9eb4e0cd3b0f1fb6rnum=9seld=958627636ic=1

Actually, I don't know if these URLs will work outside the context of
my search -- if not, go to the google advanced newsgroups search page
at:

http://groups.google.com/advanced_group_search

and enter init-param jsp in the with all of the words box (without
the quotes) and hanna in the Author box (again, without the
quotes).

Basically, it looks like a servlet definition can specify *either*
servlet-class or a jsp-file (those are the actual names of the tags
used in web.xml). Note the warnings about what form of URL to use
when you set things up this way, though.

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


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





Re: solved-Re: config.getInitParameter() still returning null

2001-03-08 Thread Milt Epstein

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-nametesty/servlet-name
jsp-filetesty.jsp/jsp-file
init-param
  param-namevar1/param-name
  param-valuevalue1/param-value
/init-param
init-param
  param-namevar2/param-name
  param-valuevalue2/param-value
/init-param
  /servlet

  servlet-mapping
servlet-nametesty/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
TITLETesty/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]




Re: solved-Re: config.getInitParameter() still returning null

2001-03-08 Thread Milt Epstein

On Thu, 8 Mar 2001, Milt Epstein wrote:

[ ... ]
 HTML
 HEAD
 TITLETesty/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

BTW, it still works if I substitute "config" for "getServletConfig()"
everywhere above.

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


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




Re: solved-Re: config.getInitParameter() still returning null

2001-03-08 Thread Markus Keller [OrcaSoft]

Hello Milt

  The value of init parameter var1 is:
  %=
  getServletConfig().getInitParameter("var1")
  %
  /P

I use this:

title%= getServletContext().getInitParameter("ApplicationName") %

instead of getServletConfig() and it works.

Markus


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




Re: solved-Re: config.getInitParameter() still returning null

2001-03-08 Thread Milt Epstein

On Fri, 9 Mar 2001, Markus Keller [OrcaSoft] wrote:

 Hello Milt
 
   The value of init parameter var1 is:
   %=
   getServletConfig().getInitParameter("var1")
   %
   /P
 
 I use this:
 
 title%= getServletContext().getInitParameter("ApplicationName") %
 
 instead of getServletConfig() and it works.

Well, they're not really interchangable, they're meant for different
purposes.  Basically, according to the 2.2 spec, there are context
parameters, and servlet parameters.  A context is basically a web
application, so context parameters are intended to be use for
application-wide parameters.  Servlet parameters are only for a
specific servlet (i.e. a subset of the application).

Sure, you can avoid using servlet parameters, and only use context
parameters, but whether that's the most appropriate and/or cleanest
way to do things depends on what you're doing.

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


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




config.getInitParameter() still returning null

2001-03-07 Thread Michael . Murphy

The config.getInitParameter() called from within a JSP page is returning null. After changing the web.xml file numerous times and trying all the suggestions from java.sun.com and the tomcat archives I still cannot resolve this problem.
Does anyone know why we can't access the init parameters?
thanks in advance

Here is what my web.xml file looks like (does not work):

web-app
  servlet
servlet-name
 Error
/servlet-name
servlet-class
  org.apache.jasper.runtime.JspServlet
/servlet-class
init-param
  param-namedebug/param-name
  param-valuetrue/param-value
/init-param
  /servlet
/web-app

and my JSP code:
%
String s = config.getInitParameter(debug);
if (s == null) {
out.println(Init param must be null!);
}
else{
out.println(Init param is +s);
}
%

Re: config.getInitParameter() still returning null

2001-03-07 Thread Chen JUn



Hi, 
Murphy

I used 
the methodconfig.getInitParameterNames() to get theEnumeration 
(pa) ofparameters.
then I 
printed them out like this:

while 
(pa.hasMoreElements()) {
 String key = (String) 
pa.nextElement();
String value = 
config.getInitParameter(key);
 out.println(key + " : " + value + 
"br");
}

the 
result is:

logVerbosityLevel : WARNING
javaEncoding : UTF-8

that 
didn't the key and value i think you wanna retrieve.

So if you 
want get the Initiate parameters of one specific servlet, in my view, you should 
use this method only in the servlet itself. Let's suppose that you had defined 
two servlet in your web.xml file. when you get the initparameters, I want to 
ask, which servlet did these parameters belong to.

think it 
would help.

J. 
Chen



  --: [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED]]: 200138 
  8:17: [EMAIL PROTECTED]: 
  config.getInitParameter() still returning nullThe config.getInitParameter() called from within a 
  JSP page is returning null. After changing the web.xml file numerous times and 
  trying all the suggestions from java.sun.com and the tomcat archives I still 
  cannot resolve this problem. Does 
  anyone know why we can't access the init parameters? thanks in advance Here is what my web.xml file looks like (does not 
  work): web-app 
servlet 
  
  servlet-name   
 Error /servlet-name 
  servlet-class   
  org.apache.jasper.runtime.JspServlet 
  
  /servlet-class  
 init-param   
  param-namedebug/param-name   
  param-valuetrue/param-value 
  /init-param   
  /servlet /web-app and my JSP 
  code: % String s = config.getInitParameter("debug"); 
  if (s == null) { out.println("Init param must be null!"); 
  } else{ out.println("Init param 
  is "+s); } %