《Servlet学习笔记》Servlet 简介

本文介绍了Servlet技术的基础概念,包括Servlet接口的功能及其实现步骤。详细解释了Servlet生命周期的方法,如初始化、服务请求处理及销毁过程,并概述了如何通过实现特定接口来创建Servlet。
摘要由CSDN通过智能技术生成

Servlet 简介:
Servlet是sun公司提供的一门用于开发动态web资源的技术。
Sun公司在其API中提供了一个servlet接口,用户若想开发一个动态web资源(即开发一个Java程序向浏览器输出数据),需要完成以下两步:
1.编写一个Java类,实现servlet接口;
2.把开发好的Java类部署到web服务器中。


jsp就是servlet
javase、javaee,servlet不属于javase而属于javaee
servlet专门文档API
Tomcat可以运行servlet,lib里面有servlet的jar包

用记事本或UltraEdit编写java程序,用Java、javac编译运行


Servlet在线APIhttp://tomcat.apache.org/tomcat-5.5-doc/servletapi/


public interface Servlet

Defines methods that all servlets must implement.

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.

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

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:

    The servlet is constructed, then initialized with the init method.
    Any calls from clients to the service method are handled.
    The servlet is taken out of service, then destroyed with the destroy method, then garbage collected and finalized.

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


Method Summary


 voiddestroy()
          Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
 ServletConfiggetServletConfig()
          Returns a ServletConfig object, which contains initialization and startup parameters for this servlet.
 java.lang.StringgetServletInfo()
          Returns information about the servlet, such as author, version, and copyright.
 voidinit(ServletConfig config)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
 voidservice(ServletRequest req,        ServletResponse res)
          Called by the servlet container to allow the servlet to respond to a request.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值