Search code examples
servletsinitializationwebsphereportal

Initial parameter of servlet deployed to IBM Portal Server cannot be found


I have defined a set of initial parameter for my servlet in web.xml file. I have deployed that servlet to a IBM Portal Server v6.1. I can read those parameters in the "Initialize parameters for servlets" page in WAS admin console. However I when I try to fetch those parameters in my code I got null. The following code will print out "number of init paras: 0"

@Override
public void init() throws ServletException {
  super.init();
  ServletContext c = getServletContext();
    for (Enumeration e = c.getInitParameterNames(); e.hasMoreElements();) {
    String s = (String)e.nextElement();
    System.out.println(">>>>>>" + s);
    ++i;
  }
  System.out.println("number of init params: " + i);
}

Any idea?


Solution

  • Okay, here I got the answer:

    @Override
    public void init() throws ServletException {
      super.init();
      // ServletContext c = getServletContext(); --ServletContext should be ServletConfig
      ServletConfig c = getServletConfig();
      for (Enumeration e = c.getInitParameterNames(); e.hasMoreElements();) {
        String s = (String)e.nextElement();
        System.out.println(">>>>>>" + s);
        ++i;
      }
      System.out.println("number of init params: " + i);
    }