Thanks Craig,
I think my issue is registering the servlet. I cannot seem to find how to do
that. How do I register a servlet with the server?

thanks
Scott



-----Original Message-----
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 13, 2001 1:51 PM
To: Tomcat Users List
Subject: Re: web.xml file confusion




On Thu, 13 Dec 2001, Purcell, Scott wrote:

> Date: Thu, 13 Dec 2001 13:34:18 -0600
> From: "Purcell, Scott" <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: web.xml file confusion
>
> Hello,
> I am working out of Martys book on Servlets, and there is an example of
> using the init block to get some parameters from the web.xml file.
> When I searched for web.xml to find it, I found one in about each
directory.
> I do not think that is right. Where should the web.xml file live?
>
> Also, Is there a way to find out (print out possibly) the parameters so I
> can see what is being read? I am asking this, because I have added the
> following snippet to my web.xml file, but the code below does NOT read
those
> params. I am confused by this, and could use some assistance.
>

There should be a web.xml file for each web application (in a WEB-INF
subdirectory), because each application is independent of the others.

The basic rules for what web.xml is all about are spelled out in the
Servlet Specificaiton, which you can download at:

  http://java.sun.com/products/servlet/download.html

(although I suspect that reading the book's discussion about web.xml would
also probably help you understand it better :-).


> Thanks
> Scott
>


> // here is part of my web.xml file The file I am running and compiles
> properly is in a package called cwp.ShowMessage. I thought all looks good,
> but maybe a second set of eyes may help.
>
>
> <web-app>
>
>  <servlet>
>       <servlet-name>ShowMessage</servlet-name>
>       <servlet-class>cwp.ShowMessage</servlet-class>
>         <init-param>
>           <param-name>message</param-name>
>         <param-value>Alert FM</param-value>
>         </init-param>
>       <init-param>
>         <param-name>repeats</param-name>
>         <param-value>20</param-value>
>       </init-param>
>     </servlet>
>
>
>  <servlet>
>       <servlet-name>ShowMessage</servlet-name>
>       <servlet-class>coreservlets.ShowMessage</servlet-class>
>         <init-param>
>           <param-name>message</param-name>
>         <param-value>Alert FM</param-value>
>         </init-param>
>       <init-param>
>         <param-name>repeats</param-name>
>         <param-value>20</param-value>
>       </init-param>
>     </servlet>
>
>
>
> // part of my class to go get the web.xml parameters message and repeats.
> public class ShowMessage extends HttpServlet {
>
>      private String message;
>      private String defaultMessage= "No Messages Today";
>      private int repeats = 1;
>
>      public void init() throws ServletException {
>          ServletConfig config = getServletConfig();
>          message = config.getInitParameter("message");
>          if (message == null) {
>              message= defaultMessage;
>          }
>
>          try {
>              String repeatString = config.getInitParameter("repeats");
>              repeats = Integer.parseInt(repeatString);
>          } catch (NumberFormatException nfe) {
>          }
>      }
>
>

The missing link is that you need to use a <servlet-mapping> to connect a
particular request URL to the <servlet> definition, then use that URL to
request the servlet's output.

> Scott Purcell
>

Craig McClanahan


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to