为什么我们使用的init()而构造 [英] Why we use init() rather Constructor

查看:129
本文介绍了为什么我们使用的init()而构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们需要的init()而非构造

请在的Servlet Applet的的参考答案。结果
如何在的init() Applet的 Servlet的区别

Please answer in reference of Servlet and Applet.
How does the init() of Applet differ from Servlet?

推荐答案

的init()方法创建并加载servlet.But的servlet实例首先通过创建构造函数(由Servlet容器完成)。我们不能写一个servlet类的构造函数与servlet的(它会抛出异常)的参数。因此,他们作为一个argument.ServletConfig对象的信息提供一个servlet关于其初始化提供一个接受ServletConfig对象一个<$​​ C $ C>的init()法(INIT)parameters.Servlet类不能声明用ServletConfig对象作为参数,不能访问ServletConfig对象的构造函数。

The init() method creates and loads the servlet.But the servlet instance is first created through the constructor (done by Servlet container). We cannot write constructors of a servlet class with arguments in servlet (It will throw Exception). So, They provided a init() method that accepts an ServletConfig object as an argument.ServletConfig object supplies a servlet with information about its initialization (init) parameters.Servlet class cannot declare a constructor with ServletConfig object as a argument and cannot access ServletConfig object.

在更多的信息:

<一个href=\"http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets6.html\">http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets6.html

这篇关于为什么我们使用的init()而构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆