File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes init(), web.xml and servlets in packages. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "init(), web.xml and servlets in packages." Watch "init(), web.xml and servlets in packages." New topic
Author

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

Mark Fletcher
Ranch Hand

Joined: Dec 08, 2001
Posts: 897
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


Mark Fletcher - http://www.markfletcher.org/blog
I had some Java certs, but they're too old now...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init(), web.xml and servlets in packages.