0

This is just curiosity, I read on some posts that is not a recommended practice create constructors on Servlets, but to be honest I have no idea why they say that, there must be a reason because I know there's an init() method to initialize things, but why can't I use the constructor to do this?

Also the Eclipse Servlet wizard generated a constructor calling super() in it, and I'm not why is this super doing there

Thanks!

CIOC
  • 1,385
  • 3
  • 19
  • 48

1 Answers1

1

It's not harmful, it's just never useful. What can you do in a constructor of a class that has no access to external resources (these may not have been provisioned for the servlet yet), no access to container resources (also may not have been provisioned for the servlet), no access to configuration, no constructor arguments, etc.

Pace
  • 41,875
  • 13
  • 113
  • 156