最近考试了呀,都没有时间来读一读心爱的Tomcat源码,终于考完了数据库,大家有没有想我,嘿嘿嘿,哎,来写一写,哎,就是玩,一次性来个大的
/**
* A servlet configuration object(配置对象) used by a servlet container to pass
* information to a servlet during initialization(在初始化期间).
* (这里的一段话描述的是ServletConfig这个接口的作用,就是一个Servlet配置对象在
* servlet初始化期间被servlet容器用来传递信息)
*/
public interface ServletConfig {
/**
* Returns the name of this servlet instance(servlet实例). The name may be provided via(经过,通过)
* server administration(服务器管理), assigned(被分配) in the web application deployment
* descriptor(部署描述符), or for(对于) an unregistered (and thus unnamed(因此没有命名)) servlet instance it
* will be the servlet's class name.
* (这句话去是有点长,就是getServletConfigName() 这个方法返回这个servlet实例
* 的名字。这个名字也许会通过服务器管理提供,会在web应用部署描述符中被分配
* 然后对于一个没有注册的servlet实例这个会成为这个servlet的名字)
*
* @return the name of the servlet instance
*/
public String getServletName();
/**
* Returns a reference(引用) to the {@link ServletContext} in which the caller(调用方) is
* executing(正在执行).
*(这里的意思是返回调用方正在执行的ServletConfig的引用,只看到这里感觉云里雾里的,看到了下一句话
才明白:返回一个被调用者用来和servlet容器交互的ServletConfig对象,虽然这里不太合适,但是在学习
安卓的时候,的确使用了一些方法都有一个参数就是上下文环境,我猜就是类似这种servletcontext,用来和
安卓里面的activity交互)
* @return a {@link ServletContext} object, used by the caller to interact
* with(交互) its servlet container
* @see ServletContext
*/
public ServletContext getServletContext();
/**
* Returns a <code>String</code> containing the value of the named
* initialization parameter(已经命名了的初始化参数), or <code>null</code> if the parameter does not
* exist(不存在).
*(这里的意思是返回一个字符串包含已经命名了的初始化参数,或者如果不存在就会返回空,哎呀,这是多么
严谨呀,如果没有指定是空的话,那么如果是一个空的ServletConfig对象调用这个获取初始化参数的方法
那么就会报一个空指针异常,所以说咱们要学习这种的严谨性)
* @param name
* a <code>String</code> specifying(指定) the name of the
* initialization parameter
* @return a <code>String</code> containing the value of the initialization
* parameter
*/
public String getInitParameter(String name);
/**
* Returns the names of the servlet's initialization parameters as an
* <code>Enumeration(枚举类型)</code> of <code>String</code> objects, or an empty
* <code>Enumeration</code> if the servlet has no initialization parameters.
*(这里的意思是将servlet初始化参数的名字作为一个枚举类型的对象来返回,或者会返回一个空的枚举对象
如果servlet没有初始化参数的话,其中,这里的枚举类型里面是由多个名字的,我猜后面的实现类里面是一个
类似数组的形式,挖个坑,为啥是枚举类型而不是别的数据类型,以后来填,嘿嘿)
* @return an <code>Enumeration</code> of <code>String</code> objects
* containing the names of the servlet's initialization parameters
*/
public Enumeration<String> getInitParameterNames();
}
总结一下,就是ServletConfig 这个抽象接口有4个抽象方法
getServletConfigName()
getServletContext()
getInitParameter()
getInitParameterNames()