3 Replies Latest reply on Sep 5, 2002 8:47 PM by Julian Gosnell

    getInitParameter()  always returns null

    Andrew Newbie

      Hi,

      I am running jboss3.0.1-jetty and I was trying to read an init-param from web.xml but I always get null as a return. Here is my init method, web.xml and the output:

      my servlet:

      public void init(ServletConfig config) throws ServletException
      {
      super.init(config);
      System.out.println("servlet name: "+getServletName());
      role = getServletConfig().getInitParameter("role");

      for (Enumeration e = getInitParameterNames() ; e.hasMoreElements() ;) {
      System.out.println("Init param: "+ getInitParameter((String)e.nextElement()));
      }
      System.out.println("role: "+role);
      }

      web.xml:


      <servlet-name>ReadQuery</servlet-name>
      <servlet-class>com.msei.query.ReadQuery</servlet-class>
      <init-param>
      <param-name>role</param-name>
      <param-value>CDSUser</param-value>
      </init-param>


      output:

      15:18:30,928 INFO [STDOUT] servlet name: com.msei.query.TestServlet
      15:18:30,932 INFO [STDOUT] Init param: anyValue
      15:18:30,934 INFO [STDOUT] Init param: false
      15:18:30,935 INFO [STDOUT] role: null

      Anybody knows why I always get null as a result for
      role? Please help.

      andrew

        • 1. Re: getInitParameter()  always returns null
          Eric Devlin Newbie

          Hey,
          I put your init params in my init() and saw a value. Admittedly, I'm using jboss301_tomcat404, but your set up seems sound. I went through something similar the other night when porting my app from jboss 2.4.3 to 3.0.1. The context-param elements were below servlet elements in the web.xml file and were not picked up by the default xml parser. This does not seem to be the case with your setup as your layout conforms to web-app_2_2.dtd and web-app_2_3.dtd. You can try a different parser (I think this is configurable with command line parameters. The only other thing that comes to mind is the DOCTYPE specified at the top of web.xml?

          • 2. Re: getInitParameter()  always returns null
            Eric Devlin Newbie

            Hey,
            This was on one line in the web.xml
            <servlet-name>asiServlet</servlet-name><servlet-class>com.alastore.servlets.asiServlet</servlet-class><init-param><param-name>role</param-name><param-value>CDSUser</param-value></init-param>

            This was in the servlet.
            public void init()
            throws ServletException
            {
            System.out.println( "************************* eric ************************" );
            System.out.println( getServletConfig().getInitParameter("role") );
            System.out.println( "************************* eric ************************" );

            This was in the output
            2002-09-04 20:18:53,895 INFO [STDOUT] ************************* eric ************************
            2002-09-04 20:18:53,895 INFO [STDOUT] CDSUser
            2002-09-04 20:18:53,895 INFO [STDOUT] ************************* eric ************************

            This is the doctype in my web.xml
            <!DOCTYPE web-app
            PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
            "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

            Hope it helps
            Eric

            • 3. Re: getInitParameter()  always returns null
              Julian Gosnell Expert

              If the problem persists, please send me the src and the resulting .war.

              Thanks,

              Jules@mortbay.com