开发者

Simple Servlet Question on ServletConfig instantiation

开发者 https://www.devze.com 2023-01-10 17:01 出处:网络
Apparently the following is generating a loop(the GenericServlet class i开发者_Go百科s calling the subclass\'s init())

Apparently the following is generating a loop(the GenericServlet class i开发者_Go百科s calling the subclass's init())

public void init() throws ServletException {

  ServletConfig c = this.getServletConfig();
  super.init(c);

}

I'm probably just doing this wrong. Thank you guys in advance!


Remove the super.init(c); line. You only need to call this in init(ServletConfig) method, not in the init() without ServletConfig argument. That's also exactly what the linked javadoc tells:

A convenience method which can be overridden so that there's no need to call super.init(config).

The infinite loop is indeed caused because the default init(config) implementation is under the hoods calling the init().


No need for the super.init(c);. Remove it.

0

精彩评论

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