public abstract class GenericServlet
    implements Servlet, ServletConfig, java.io.Serializable
{

    private transient ServletConfig config;
    /**
     * Does nothing. All of the servlet initialization
     * is done by one of the <code>init</code> methods.
     */
    //空构造函数,所有的servlet初始化已经被init函数执行
    public GenericServlet() { }

   /**
     * Called by the servlet container to indicate to a servlet that the
     * servlet is being taken out of service.  See {@link Servlet#destroy}.
     */
    //servlet容器调用,表明servlet被移除服务
    public void destroy() {
    }
    /**
     * Returns a <code>String</code> containing the value of the named
     * initialization parameter, or <code>null</code> if the parameter does
     * not exist.  See {@link ServletConfig#getInitParameter}.
     * <p>This method is supplied for convenience. It gets the
     * value of the named parameter from the servlet's
     * <code>ServletConfig</code> object.
     * @param name 		a <code>String</code> specifying the name
     *				of the initialization parameter
     * @return String 		a <code>String</code> containing the value
     *				of the initialization parameter
     */
    //获得初始化参数name的值
    public String getInitParameter(String name) {
    	return getServletConfig().getInitParameter(name);
    }
    //初始化参数枚举
    public Enumeration getInitParameterNames() {
    	return getServletConfig().getInitParameterNames();
    }
    /**
     * Returns this servlet's {@link ServletConfig} object.
     * @return ServletConfig 	the <code>ServletConfig</code> object that initialized this servlet
     */
    //获得servlet的初始化对象
    public ServletConfig getServletConfig() {
	return config;
    }
    /**
     * Returns a reference to the {@link ServletContext} in which this servlet
     * is running.  See {@link ServletConfig#getServletContext}.
     * <p>This method is supplied for convenience. It gets the
     * context from the servlet's <code>ServletConfig</code> object.
     * @return ServletContext 	the <code>ServletContext</code> object passed to this servlet by the <code>init</code>method
     */
    //返回正在运行的servlet的ServletContext,
    public ServletContext getServletContext() {
    	return getServletConfig().getServletContext();
    }
    /**
     * Returns information about the servlet, such as  author, version, and copyright.
     * By default, this method returns an empty string.  Override this method
     * to have it return a meaningful value.  See {@link Servlet#getServletInfo}.
     * @return String 		information about this servlet, by default an empty string
     */
    //获得Servlet信息
    public String getServletInfo() {
    	return "";
    }
    /**
     * Called by the servlet container to indicate to a servlet that the
     * servlet is being placed into service.  See {@link Servlet#init}.
     * <p>This implementation stores the {@link ServletConfig}  object it receives from the servlet container for later use. When overriding this form of the method, call
     * <code>super.init(config)</code>.
     * @param config 			the <code>ServletConfig</code> object that contains configutation information for this servlet
     * @exception ServletException 	if an exception occurs that interrupts the servlet's normal operation
     * @see UnavailableException
     */
    //servlet容器进行调用,表明这个Servlet被放置进服务
    public void init(ServletConfig config) throws ServletException {
    	this.config = config;
    	this.init();
    }

    /**
     * A convenience method which can be overridden so that there's no need
     * to call <code>super.init(config)</code>.
     * <p>Instead of overriding {@link #init(ServletConfig)}, simply override
     * this method and it will be called by<code>GenericServlet.init(ServletConfig config)</code>.
     * The <code>ServletConfig</code> object can still be retrieved via {@link #getServletConfig}.
     * @exception ServletException 	if an exception occurs that interrupts the servlet's normal operation
     */

    public void init() throws ServletException {

    }
    /**
     * Writes the specified message to a servlet log file, prepended by the
     * servlet's name.  See {@link ServletContext#log(String)}.
     * @param msg 	a <code>String</code> specifying
     *			the message to be written to the log file
     */
     //写Servlet名和信息日志
    public void log(String msg) {
    	getServletContext().log(getServletName() + ": "+ msg);
    }
    /**
     * Writes an explanatory message and a stack trace
     * for a given <code>Throwable</code> exception
     * to the servlet log file, prepended by the servlet's name.
     * See {@link ServletContext#log(String, Throwable)}.
     * @param message 		a <code>String</code> that describes the error or exception
     * @param t			the <code>java.lang.Throwable</code> error or exception
     */

    public void log(String message, Throwable t) {
	getServletContext().log(getServletName() + ": " + message, t);
    }
    /**
     * Called by the servlet container to allow the servlet to respond to
     * a request.  See {@link Servlet#service}.
     *
     * <p>This method is declared abstract so subclasses, such as
     * <code>HttpServlet</code>, must override it.
     * @param req 	the <code>ServletRequest</code> object	that contains the client's request
     * @param res 	the <code>ServletResponse</code> object that will contain the servlet's response
     * @exception ServletException 	if an exception occurs that interferes with the servlet's normal operation occurred
     * @exception IOException 		if an input or output exception occurs
     */
    //servlet 容器调用来运行Servlet 对请求进行回复
    public abstract void service(ServletRequest req, ServletResponse res)
	throws ServletException, IOException;
    /**
     * Returns the name of this servlet instance.
     * See {@link ServletConfig#getServletName}.
     * @return          the name of this servlet instance
     */
    //Servlet名称
    public String getServletName() {
        return config.getServletName();
    }
}

Java-GenricServlet的更多相关文章

  1. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  2. Java Servlet(五):GenericServlet与Servlet、HttpServlet之间的关系(jdk7+tomcat7+eclipse)

    本篇主要记录下,对GenericServlet的作用理解,及其与Servlet/HttpServlet之间的关系. 示例完成业务: 1.新建一个login.jsp页面,要求改页面能输入username ...

  3. 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题

    背景起因: 记起以前的另一次也是关于内存的调优分享下   有个系统平时运行非常稳定运行(没经历过大并发考验),然而在一次活动后,人数并发一上来后,系统开始卡. 我按经验开始调优,在每个关键步骤的加入如 ...

  4. Elasticsearch之java的基本操作一

    摘要   接触ElasticSearch已经有一段了.在这期间,遇到很多问题,但在最后自己的不断探索下解决了这些问题.看到网上或多或少的都有一些介绍ElasticSearch相关知识的文档,但个人觉得 ...

  5. 论:开发者信仰之“天下IT是一家“(Java .NET篇)

    比尔盖茨公认的IT界领军人物,打造了辉煌一时的PC时代. 2008年,史蒂夫鲍尔默接替了盖茨的工作,成为微软公司的总裁. 2013年他与微软做了最后的道别. 2013年以后,我才真正看到了微软的变化. ...

  6. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  7. 死磕内存篇 --- JAVA进程和linux内存间的大小关系

    运行个JAVA 用sleep去hold住 package org.hjb.test; public class TestOnly { public static void main(String[] ...

  8. 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用

    有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...

  9. Java多线程基础学习(二)

    9. 线程安全/共享变量——同步 当多个线程用到同一个变量时,在修改值时存在同时修改的可能性,而此时该变量只能被赋值一次.这就会导致出现“线程安全”问题,这个被多个线程共用的变量称之为“共享变量”. ...

  10. Java多线程基础学习(一)

    1. 创建线程    1.1 通过构造函数:public Thread(Runnable target, String name){}  或:public Thread(Runnable target ...

随机推荐

  1. Android开发之Path类使用详解,自绘各种各样的图形!

    玩过自定义View的小伙伴都知道,在View的绘制过程中,有一个类叫做Path,Path可以帮助我们实现很多自定义形状的View,特别是配合xfermode属性来使用的时候.OK,那我们今天就来看看P ...

  2. FORM界面批量处理-全选框实现

    全选框实现方法多种多样,这里只介绍两种 方法一:触发器式,优点程序简单,缺点颜色单调不突出 1.      在数据块和控制块上分别创建check box 2.      设置check box选中与为 ...

  3. activiti processEngineLifecycleListener使用

    1.1.1. 前言 实际开发中,有需求如下: 第一:项目启动部署的时候,我们需要监控activiti 工作流引擎是否真正的已经实例化启动了,这里说的是工作流引擎的启动,不是流程实例的启动,对此要特别说 ...

  4. ubuntu挂载的NTFS文件编译失败问题

    错误: 编译Android源代码时候出现,权限拒绝的错误 解决方法: sudo apt-get install ntfs-config sudo ntfs-config 我的微信二维码如下,欢迎交流讨 ...

  5. [Centos]openvpn 服务端的安装(easy-rsa3)

    VPN在办公和fan墙领域有着广泛的应用,  我们小办公网最近可能会用到,先学学来着 vpn的server需要有公网ip,客户端可以在多种环境下使用 概念 PKI:Public Key Infrast ...

  6. 19 主线程向子线程发送信息(handler)

    package com.fmy.handler; import android.app.Activity; import android.os.Bundle; import android.os.Ha ...

  7. CUSTOM.PLL的使用

    在开发中对系统标准form的修改一般不建议修改系统原有FORM,对所需要修改的内容一般写在CUSTOM.PLL里即可,应为每个form运行的时候都会调用CUSTOM.PLL具体概念性东西可参考网上资料 ...

  8. (NO.00005)iOS实现炸弹人游戏(十一):怪物之火精灵

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 从本篇开始我们一次介绍一下游戏中敌人的制作过程.看过第一篇的小 ...

  9. 【翻译】Ext JS 6.2 早期访问版本发布

    原文:Announcing Ext JS 6.2 Early Access 非常开心,Sencha Ext JS 6.2早期访问版本今天发布了.早期访问版本的主要目的是为了让大家进行测试并评估Ext ...

  10. 详解EBS接口开发之库存事务处理批次更新

    库存事务处理批次有时候出现导入错误需要更新可使用次程序更新,批次导入可参考博客 详解EBS接口开发之库存事务处理-物料批次导入 http://blog.csdn.net/cai_xingyun/art ...