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;
}
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);
}
精彩评论