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.

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) {
         }
     }
 

Scott Purcell


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

Reply via email to