Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init(), web.xml and servlets in packages.

 
Mark Fletcher
Ranch Hand
Posts: 897
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I was wondering if you could help me understand an area of java servlets thats causing me some confusion, specifically, a servlet in a package that uses parameters in the web.xml file.
Some info first:
Im using Tomcat 4.0.3 with J2SE 1.4. The Servlet container is configured to run on port 80.
Ive just started using Java Servlets, and Im working through Marty Halls book "CoreServlets and Java Server pages" Im trying to understand the example in Chapter 2 of the book where a Servlet called ShowMessages reads paramters from the web.xml file. The ShowMessages class is a part of the coreservlets package.
I can normally access servlets that are in the coreservlet package by accessing
http://localhost/servlet/coreservlets.<MyServletClass>
where <MyServletClass> is any Servlet class in the coreservlets package.
Now if I run the ShowMessage servlet on
http://localhost/servlet/coreservlets.ShowMessage
The servlet is run, but no parameters are loaded.
If I just run
http://localhost/servlet/ShowMessage
The servlet is run, and the parameters in the web.xml file are read.
For the sake of typing, the ShowMessage.java and the web.xml files are exactly the same as that in the coreservlets book.
Any explanation would be greatly appreciated
Mark
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the reason for the following:
Now if I run the ShowMessage servlet on
http://localhost/servlet/coreservlets.ShowMessage
The servlet is run, but no parameters are loaded.

is that with this URL, the servlet container finds the servlet without going through the web.xml data at all. This is a mode of operation that is left over from earlier servlet APIs - before Sun laid down the law about the use of web.xml for configuring servlets.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic