理解Servlet

Defines methods that all servlets must implement.

<p>A servlet is a small Java program that runs within a Web server.
Servlets receive and respond to requests from Web clients,
usually across HTTP, the HyperText Transfer Protocol.

<p>To implement this interface, you can write a generic servlet
that extends
<code>javax.servlet.GenericServlet</code> or an HTTP servlet that
extends <code>javax.servlet.http.HttpServlet</code>.

定义所有的servlet都必须实现的方法。

Servlet是一个运行在web服务器上的Java程序。Servlets脚本从web客户端接收和响应请求,通常是通过HTTP(超文本传输协议).

你可以写一个通用的Servlet类来实现这个接口,再让相应的类来继承这个通用类(GenericServlet、HttpServlet)

<p>This interface defines methods to initialize a servlet,
to service requests, and to remove a servlet from the server.
These are known as life-cycle methods and are called in the
following sequence:
<ol>
<li>The servlet is constructed, then initialized with the <code>init</code> method.
<li>Any calls from clients to the <code>service</code> method are handled.
<li>The servlet is taken out of service, then destroyed with the
<code>destroy</code> method, then garbage collected and finalized.
</ol>

这个接口定义了初始化Servlet,处理请求,销毁Servlet的方法,下面的生命周期方法按如下顺序执行:

Servlet类被构造器创造出来,执行init方法进行初始化

任何从客户端发来的请求都会被相应的方法处理

停止使用Servlet时执行销毁的方法,等待垃圾回收器GC他

<p> In addition to the life-cycle methods, this interface
provides the <code>getServletConfig</code> method, which the servlet
can use to get any startup information, and the <code>getServletInfo</code>
method, which allows the servlet to return basic information about itself,
such as author, version, and copyright.

除了生命周期以外的方法,这个接口还提供配置servlet类的方法,这个方法可以使任何使用它的人得到启动信息,getServletInfo返回这个Servlet的基本信息,包括作者、版本号、公司啥的。

--------------------------------------------------------------------------------------------

综上,servlet就是个运行在服务器端的Java程序,实现了他的接口的都可以理解成Servlet类,Servlet接口包含生命周期函数和获取servlet信息的函数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值