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

    getInitParameter()  always returns null

    Andrew Newbie


      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
      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);




      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.


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

          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

            This was on one line in the web.xml

            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"

            Hope it helps

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

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