Sure:

  public void init(ServletConfig config)
      throws ServletException {
    // Always call super.init
    super.init(config);
    message = config.getInitParameter("message");
    if (message == null) {
      message = defaultMessage;
    }
    try {
      String repeatString = config.getInitParameter("repeats");
      repeats = Integer.parseInt(repeatString);
    } catch(NumberFormatException nfe) {
      // NumberFormatException handles case where repeatString
      // is null *and* case where it is something in an
      // illegal format. Either way, do nothing in catch,
      // as the previous value (1) for the repeats field will
      // remain valid because the Integer.parseInt throws
      // the exception *before* the value gets assigned
      // to repeats.
    }
  }

it's form the book "core Servlets..." by Marty Hall


-----Original Message-----
From: Shapira, Yoav [mailto:[EMAIL PROTECTED]] 
Sent: Friday, June 07, 2002 4:11 PM
To: Tomcat Users List
Subject: RE: Problem With Params In Web.xml

Howdy,
Can you post your init() method?  

Does getServletConfig().getInitParameter("message") return null?
What does getServletConfig().getInitParameterNames() return?

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Marek, Tomas [mailto:[EMAIL PROTECTED]]
>Sent: Friday, June 07, 2002 10:04 AM
>To: [EMAIL PROTECTED]
>Subject: Problem With Params In Web.xml
>
>Guys,
>
>could anybody help, please? Having a servlet reading parameters in
init()
>method but it reads nothing. The servlet is in path
>install_dir/webapps/ROOT/WEB-INF/classes/examples and web.xml is in
path
>install_dir/webapps/ROOT/WEB-INF.
>The content of web.xml looks like the following:
>
><?xml version="1.0" encoding="ISO-8859-1"?>
>
><!DOCTYPE web-app
>    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
>    "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd";>
>
><web-app>
>  <servlet>
>    <servlet-name>
>      ShowMsg
>    </servlet-name>
>
>    <servlet-class>
>      examples.ShowMessage
>    </servlet-class>
>
>    <init-param>
>      <param-name>
>        message
>      </param-name>
>      <param-value>
>        blablabla
>      </param-value>
>    </init-param>
>
>    <init-param>
>      <param-name>
>        repeats
>      </param-name>
>      <param-value>
>        5
>      </param-value>
>    </init-param>
>  </servlet>
></web-app>
>
>Does anybody have an idea where's the problem? Thanks in advance for
any
>clue.
>
>tom

--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to