Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 68136 invoked by uid 500); 20 Aug 2001 15:24:43 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: tomcat-user@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 68126 invoked from network); 20 Aug 2001 15:24:43 -0000 Received: from h32.sny.collab.net (HELO icarus.apache.org) (64.208.42.42) by h31.sny.collab.net with SMTP; 20 Aug 2001 15:24:43 -0000 Received: (qmail 41814 invoked by uid 1059); 20 Aug 2001 15:19:42 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 20 Aug 2001 15:19:42 -0000 Date: Mon, 20 Aug 2001 08:19:42 -0700 (PDT) From: "Craig R. McClanahan" Sender: craigmcc@localhost To: tomcat-user@jakarta.apache.org Subject: Re: New to servlets: Parameter initialisation in web.xml In-Reply-To: <20010820130009.87198.qmail@web10307.mail.yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE X-Spam-Rating: localhost 1.6.2 0/1000/N X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N On Mon, 20 Aug 2001, chris hutchings wrote: > Hi, > i am new to servlets, and i am working through the > examples in a servlets book, > =20 > I have to set some parameters in web.xml > that are used in one of the examples init() method. > Unfortunately the initialisation is not working > properly and i get a 'null' when I print out the > variable. >=20 > what can i be doing wrong. >=20 In order for servlet initialization parameters to be accessed by your servlet, you have to do *four* things: * Set up the entries inside your definition. * Make sure your servlet class is under /WEB-INF/classes (or in a JAR file under /WEB-INF/lib) in a directory structure that reflects the package names (just like any other Java class). * Set up a that maps some particular request URI to your servlet. * Access the server using that request URI. > i have used the web.xml in ROOT\WEB-INF=20 >=20 Let's carry this out with an example. Assume you add the following to the ROOT/WEB-INF/web.xml file in the appropriate places): My Servlet com.mycompany.mypackage.MyServlet foo bar My Servlet /mypath Now, assuming that you have your servlet class in the right place (ROOT/WEB-INF/classes/com/mycompany/mypackage/MyServlet.class), you'll be able to restart Tomcat and access your servlet like this: http://localhost:8080/mypath and it will be able to read the initialization parameter "foo". The URL above works because you were modifying the ROOT webapp. If you had modified the "examples" webapp instead, the only difference would have been in the URL: http://localhost:8080/examples/mypath For more information about valid parameters in web.xml, you should download and read the Servlet Specification at: http://java.sun.com/products/servlet/download.html > Also I have added a context path to server.xml, so > that I can use my own named directories. > But this does not seem to work either. >=20 > I can run servlets in the > \webapps\ROOT\WEB-INF\classes folder, but I can not > get the servlets in the examples directory to work.=20 >=20 > It must be something basic, with the configuration but > what I do not know =85=85 >=20 > Chris=20 >=20 Craig McClanahan