super.init(config) calls init(config) in javax.servlet.GenericServlet

  public void init(ServletConfig config) throws ServletException
  {
    _config = config;
    log("init");
    init();
  }

If the call is missing, methods like getInitParameter, getServletName,
etc. do not work as well as logging methods. But, I think, there is not
serious consequences. There could be some problems if your servlet calls
getSelvletConfig to do any clean up job.

I think is a better practice to override init() method and not
init(ServletConfig config) method.

public void init() throws ServletException {
   sc = getSelvletConfig().getServletContext() ;
  try {
    env = (Context) new InitialContext().lookup("java:comp/env");
        ...

Or even better
public void init() throws ServletException {
        sc = getServletContext() ;
        . . .

In init() method super().init() can be omitted safely.


Andrea Sodomaco
 
Andrea Sodomaco Consulenze Informatiche
Via Giacometti, 4 - 34146 TRIESTE
Tel.: 040 281648 / 338 3565702 - Fax: 040 46069349
www.sodomaco.it


-----Messaggio originale-----
Da: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Per conto di John Steel
Inviato: martedì 24 aprile 2007 17.05
A: resin-interest@caucho.com
Oggetto: [Resin-interest] What happens if you *don't* call
super.init(...)?


Just found (and corrected) a probable howler in a pretty busy servlet:

public void init(ServletConfig config) throws ServletException {
  super.init(config);
  sc = config.getServletContext();
  try {
    env = (Context) new InitialContext().lookup("java:comp/env");
    pool = (javax.sql.DataSource)
env.lookup(System.getProperty("app.dbid"));
  } catch (NamingException e) {
    e.printStackTrace();
  }
  Locale.setDefault(Locale.ENGLISH);
  logConfPath = sc.getRealPath("")+"WEB-INF/log/log.properties";
}

The super.init() line was missing. We didn't notice because it was
serving correctly, but have seen a gradual slowdown over a few days
usually cured by a restart. Could the missing line have caused it? If
not, what bad side effects could we have expected please?

-- 
--------------------------
http://www.phonewebcam.com
[EMAIL PROTECTED]



_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest



_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to