web 开发分为两种:静态开发(使用html)和动态开发(使用servlet/jsp,jsp就是servlet,ASP ,PHP)

所以servlet是sun公司提供的一门专门用于开发动态web资源的技术

sun公司在API中提供一个servlet接口,用户如果想开发一个动态web资源,需要完成二步

1. 编写一个Java类,实现servlet接口

2. 把开发好的Java类部署到web服务器

sun公司已经实现了servlet的两个默认实现类,所以我们在使用它的时候只需要继承这两个类就行了

  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.

  生命周期相关的方法:(比如人这个对象20岁上大学,25岁找工作)生命中某个特点时期必定要执行的方法。

Servlet生命周期:

  浏览器向服务器发送请求

  第一次创建servlet实例对象

  调用servlet的init方法完成对象的初始化

  创建代表请求的request和代表相应的response对象,然后调用servlet的service方法相应客户端请求

  Service方法执行,向代表客户机响应的response对象写入向客户机输出的数据

  Service方法返回,此时response里面有数据

  服务器从response里取出数据,构出一个http响应回写给客户机

  Servlet对象创建后会驻留在服务器中,为所有用户服务

  当关掉web服务器后会消失

  并调用destroy()

  客户的每次请求都会在服务器中创建一个response和request对象,但是这两个对象的生命周期很短,请求结束,对象即销毁

所以,默认的servlet对象是在用户请求的时候才创建,并不是在启动服务器的时候创建,但是如果加上一个标签:

	<servlet>
<servlet-name>ServelDemol</servlet-name>
<servlet-class>cn.itcast.ServelDemol</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>

  就会在启动服务器的时候就创建servlet对象

学好servlet的关键就是知道在创建servlet对象的同时,也同时创建了哪些相关对象,有以下几个:

Request

Response

ServletConfig

ServletContext

Session

Cookie

servlet简介的更多相关文章

  1. Servlet基础(一) Servlet简介 关键API介绍及结合源码讲解

    Servlet基础(一) Servlet基础和关键的API介绍 Servlet简介 Java Servlet是和平台无关的服务器端组件,它运行在Servlet容器中. Servlet容器负责Servl ...

  2. Servlet简介与Servlet和HttpServlet运行的流程

    1.Servlet      [1] Servlet简介         > Server + let         > 意为:运行在服务器端的小程序.         > Ser ...

  3. JavaEE:Servlet简介及ServletConfig、ServletContext

    Servlet简介 1.Servlet是sun公司提供的一门用于开发动态web资源的技术*静态web资源:固定数据文件*动态web资源:通过程序动态生成数据文件2.Servlet技术基于Request ...

  4. Servlet简介及使用

    javaweb学习总结(五)——Servlet开发(一) 一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口 ...

  5. servlet简介及生命周期

    Servlet 简介 Servlet 是什么? Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上 ...

  6. (一)Servlet简介

    相关名词解释 HTML:Hyper Text Markup Language,超文本标记语言 HTTP:Hyper Text Transfer Protocol,超文本传输协议 URL:Uniform ...

  7. 【Servlet】(1)Servlet简介、Servlet底层原理、Servlet实现方式、Servlet生命周期

    一.Servlet简介 1.Servlet定义: Servlet(Server Applet)是Java Servlet的简称,是为小服务程序或服务连接器,用Java编写的服务器端程序,主要功能在于交 ...

  8. 1.1(学习笔记)Servlet简介及一个简单的实例

    一.Servlet简介 Servlet是使用Java语言编写的服务器端程序,可以生产动态的Web界面. 主要运行在服务器端,Servlet可以方便的处理客户端传来的HTTP请求,并返回一个响应. 二. ...

  9. Servlet学习笔记【1】--- 背景和基础知识(CGI、Web服务器发展史、Servlet简介、任务、继承结构)

    本文主要讲Servlet的基础知识和背景知识. 1 CGI简介 CGI(Common Gateway Interface 公共网关接口)是WWW技术中最重要的技术之一,有着不可替代的重要地位.CGI是 ...

  10. 二:Servlet简介

    一.Servlet简介 1.什么是Servlet Servlet 运行在服务端的Java小程序,是sun公司提供一套规范(接口),用来处理客户端请求.响应给浏览器的动态资源.但servlet的实质就是 ...

随机推荐

  1. ASP.NET Excel数据导出数据库

    /// <summary> /// 根據gridview導出excel /// </summary> /// <param name="ctl"> ...

  2. Nhibernate主子表查询

    假如有AB两表,A为主,B为子:已知A表ID,查B表数据 ICriteria criteriaTotal = session.CreateCriteria<B>().CreateCrite ...

  3. 使用Physics_Body_Editor获得json文件的类

    [转自]:http://www.cocoachina.com/bbs/read.php?tid=209290 工具介绍,json文件获得方法,请参考原帖 MyBodyParser.h // // My ...

  4. OC 字符和日期的互转

    需要用到NSDateFormatter这个类. 1.字符串转换为日期 [plain]NSDateFormatter* dateFormat = [[NSDateFormatter alloc] ini ...

  5. yzoi2226最小步数的详细解法

    Description - 问题描述 在各种棋中,棋子的走法总是一定的,如中国象棋中马走“日”.有一位小学生就想如果马能有两种走法将增加其趣味性,因此,他规定马既能按“日”走,也能如象一样走“田”字. ...

  6. http拦截器interceptors

    在服务里配置$httpProvider.interceptors的相关参数 包含 request请求拦截 response响应拦截 requestError请求错误抛出 responseError响应 ...

  7. shell 脚本中 命令

    终端工具tput和stty是两款终端处理工具tput cols,lines,longname,cpu 100 100 输入密码时,不能让输入的内容显示出来.用stty #!/bin/bash #Fil ...

  8. Flask 富文本编辑器

    XHEditor http://segmentfault.com/blog/digwtx/1190000002439076 CKeditor http://segmentfault.com/blog/ ...

  9. 【转】HTML5 LocalStorage 本地存储

    原文见:http://www.cnblogs.com/xiaowei0705/archive/2011/04/19/2021372.html 说到本地存储,这玩意真是历尽千辛万苦才走到HTML5这一步 ...

  10. Python面向对象OOP

    一 OOP     与C++和Java一样,Python同样具有OOP设计. 过程式:从前到后,一条一条,机器能接受的顺序性方式:方式大概为"首先你应该做什么,第二应该做什么,高级点的做点假 ...