开发者

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

开发者 https://www.devze.com 2023-03-22 01:13 出处:网络
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 servl

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;
  }
  Syste开发者_如何转开发m.out.println("number of init params: " + i);
}

Any idea?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号