zoukankan      html  css  js  c++  java
  • servlet生命周期

    1.Servlet 遵循的过程:
    • Servlet 初始化后调用 init () 方法。
    • Servlet 调用 service() 方法来处理客户端的请求。
    • Servlet 销毁前调用 destroy() 方法。
    • 最后,Servlet 是由 JVM 的垃圾回收器进行垃圾回收的。
    2.init()方法的定义
    public void init() throws ServletException { // 初始化代码... }
    3.service() 方法
    service() 方法是执行实际任务的主要方法。
    service()方法的特征:
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException{ }
    service() 方法由容器调用,service 方法在适当的时候调用 doGet、doPost、doPut、doDelete 等方法。所以不用对 service() 方法做任何动作,只需要根据来自客户端的请求类型来重写 doGet() 或 doPost() 即可。
    4.doGet()方法
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Servlet 代码 }
    5.doPost() 方法
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Servlet 代码 }
    6.destroy() 方法
    destroy() 方法可以让您的 Servlet 关闭数据库连接、停止后台线程、把 Cookie 列表或点击计数器写入到磁盘,并执行其他类似的清理活动。
    destroy 方法定义如下所示:
    public void destroy() { // 终止化代码... }

  • 相关阅读:
    vue-cli element axios sass 安装
    Rem-- ui图与适配手机的px换算
    REM
    Canvas画半圆扇形统计图
    在vue中安装SASS
    在vue中引用.SCSS的公用文件
    Echart--折线图手柄触发事件
    vue 脚手架webpack打包后,解决能看到vue源码的问题
    js 函数 /变量/ 以及函数中形参的预解析的顺序
    【算法日记】4.递归和快速排序
  • 原文地址:https://www.cnblogs.com/zyj3955/p/14081502.html
Copyright © 2011-2022 走看看