Servlet初始化调用init方法:(依次执行)
1.调用初始化init()
public abstract void init(ServletConfig paramServletConfig)
throws ServletException;
2.init方法中加载ServletConfig接口一些配置信息
public interface ServletConfig {
public abstract String getServletName();
public abstract String getInitParameter(String paramString);
public abstract ServletContext getServletContext();
public abstract Enumeration getInitParameterNames();
}
3.ServletConfig接口配置ServletContext等,以及初始化参数方法,同时加载创建全局的储存信息的空间ServletContext,Servlet上下文提供对应用程序中所有Servlet所共有的各种资源和功能的访问.
ServletContext接口提供一系列方法,最常用的几个方法:
public abstract interface ServletContext {
//获取请求转发对象,param:path相对于SrvletContext路径(/x)
public abstract RequestDispatcher getRequesDispatcher(String path);
//获取请求转发对象,param:path相对于SrvletContext路径(/x)
public abstract RequestDispatcher getNamedDispatcher(String path);
public abstract String getContextPath();
public abstract ServletContext getContext(String paramString);
public abstract Set getResourcePaths(String paramString);
public abstract URL getResource(String paramString)
throws MalformedURLException;
public abstract InputStream getResourceAsStream(String paramString);
}
4.在ServletContext接口中的RequestDispathcher接口有:
public abstract interface RequestDispatcher
{
public abstract void forward(ServletRequest paramServletRequest, ServletResponse paramServletResponse)
throws ServletException, IOException;
public abstract void include(ServletRequest paramServletRequest, ServletResponse paramServletResponse)
throws ServletException, IOException;
}
只有请求转发和include方法