Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to set up Init Params  RSS feed

 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, I'm using Tomcat 4.0.6. I'm trying to simply set up an init-param for a servlet in the deployment descriptor (web.xml) and then print the value of that init-param from the servlet. Unfortunately, I can't seem to get this to work. This is what I have:
My Servlet:

My deployment descriptor file (this is the entire file):

I would expect executing the servlet to print:
Init param: test
but it's not working. Instead, I get this:
Init param: null

Anyone have any ideas why I can't seem to get this init parameter to set up properly?
Thanks,
Corey
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Corey
I cut and paste the code you supplied and it worked perfectly for me, printing "Init param: test" every time when run.
I'm using Tomcat 4.0.4. Have you made any other alterations to the Tomcat configuration? Did you restart Tomcat after adding the init-params to your deployment descriptor?
There's gotta be something different out there
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mark howard:
I cut and paste the code you supplied and it worked perfectly for me, printing "Init param: test" every time when run.
I'm using Tomcat 4.0.4. Have you made any other alterations to the Tomcat configuration? Did you restart Tomcat after adding the init-params to your deployment descriptor?

Honestly, I just downloaded and set up Tomcat 4.0.6 today. I installed it in the default directory (C:\jakarta-tomcat-4.0.6) and set up an environment variable named CATALINA_HOME to point to that directory. Then, I put my app into a directory under the webapps folder. That's really all I've done.
I got the app up and running and then tried to add the deployment descriptor (it's in the WEB-INF directory). Is there any way to tell what's going wrong?
I've restarted the app server dozens of times, but to no avail. I've even created a new app that does nothing but prints an init param, but that isn't working, either.
At this point, I'm at a loss even for a way to debug the problem. If anyone has any ideas, please shoot them my way.
Thanks,
Corey
[ January 27, 2003: Message edited by: Corey McGlone ]
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be a dumb question, but how are you triggering the servlet? Address bar? HTML link?
Is the deployment descriptor configuration definitely being applied, using the defined servlet name "controller".
Just trying to establish whether Tomcat is using the deployment descriptor and init params as expected.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mark howard:
This might be a dumb question, but how are you triggering the servlet? Address bar? HTML link?
Is the deployment descriptor configuration definitely being applied, using the defined servlet name "controller".
Just trying to establish whether Tomcat is using the deployment descriptor and init params as expected.

Well, originally, I was triggering the servlet from a link in a JSP. The new one I made, however, was triggered directly from the address bar (I went to http://localhost:8080/myTest/servlet/MyServlet). In both cases, the init parameter failed to print.
One thing I wonder about is the fact that I'm not really referring to that servlet as "controller" anywhere except in the web.xml file. I don't even trigger it by that name, I trigger it by its true class name. Is that wrong?
Thanks,
Corey
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know what, that's it! I found that if I don't refer to the servlet by the name I supplied, the init parameter does not get set. I've found that if I do trigger it by the name I give the servlet in the web.xml file, it does get set.
Obviously, I've got a lot to learn about servlets and deploying these applications, but can anyone explain me why this is the case? Why don't the init parameters simply get set for all of the servlets right away? When, and why, does that web.xml file get read?
Thanks,
Corey
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Corey
Glad to hear it worked!
I'm also pretty new to this Servlet/JSP game, but I've found that you need to refer to the components you define in the deployment descriptor in the appropriate manner in order to get your expected results.
The deployment descriptor is referenced by the Servlet container when it is started. The container creates an instance of each servlet defined in the descriptor file and wraps any specified init-param elements into a ServletConfig object, which is passed to the init() method when the servlet is requested.
Cheers
Mark.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!