[英]Is it mandatory to override servlet init() or init(ServletConfig config) and destroy() methods
您能否告诉我,在我们编写的新servlet(ex:HelloServlet)中重写init()或init(ServletConfig配置)和destroy()方法是强制性的吗?
These two methods are a part of the javax.servlet.Servlet
interface; 这两个方法是
javax.servlet.Servlet
接口的一部分。 so, they must somehow be implemented, either by your servlet or by a base class of your servlet. 因此,必须以某种方式由您的servlet或servlet的基类实现它们。
Usually, you'd write a servlet that does not directly implement javax.servlet.Servlet
, but extend the javax.servlet.GenericServlet
class or the javax.servlet.http.HttpServlet
class. 通常,您会编写一个不直接实现
javax.servlet.Servlet
的servlet,而是扩展javax.servlet.GenericServlet
类或javax.servlet.http.HttpServlet
类。 If you extend either of these, then you don't have to override init
or destroy
- as long as the superclass' implementation is OK with you. 如果您扩展了其中任何一个,那么您就不必重写
init
或destroy
只要超类的实现对您来说就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.