首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

解读 Servlet 源码:GenericServlet,ServletConfig,ServletContext

那么ServletConfig 对象肯定以后要在Service 方法中使用,怎么才能保证ServletConfig 对象在Service方法中能够使用呢?...ServletConfig 从上面的知识我们知道了 : Tomcat 服务器先创建了 ServletConfig 对象,然后调用init()方法,将ServletConfig对象传给了init()方法。...先来一波,自问自答: ServletConfig 是什么? package javax.servlet; 显然 ServletConfig 是一个接口。 图片 谁去实现了这个接口呢 ?...Tomcat 服务器(WEB服务器) 创建了ServletConfig 对象,在创建Servlet 对象的时候,同时创建ServletConfig 对象....这个是 :一个 Servlet 对象就一 个 ServletConfig 对象,有 100 个 Servlet 对象就有 100 个 ServletConfig 对象。

59930

Java Web Servlet (Part B)- ServletConfig & ServletContext

一、ServletConfig类使用 ServletConfig类时Servlet程序的配置信息类,使用Servlet可以实现 获取Servlet程序的别名,既web.xml中配置servlet-name..., 其中init方法中包含了ServletConfig类作为方法参数,可以直接使用servletConfig获取web.xml中的一些配置 @Override public void init(ServletConfig...@Override public void init(ServletConfig servletConfig) throws ServletException { System.out.println...对象都是由Tomcat负责创建的,Servlet程序默认是第一次访问的时候创建,ServletConfig是每个Servlet程序创建是都会创建一个对应的ServletConfig对象 在其他地方使用ServletConfig...对象 在其他方法中使用ServletConfig可以直接调用getServletConfig方法来获取ServletConfig对象;在controller包中新增HalloServlet,在doPost

29620

JavaWeb(一)Servlet中的ServletConfig与ServletContext

接下来我们要说的是Servlet的四个类:   ServletConfig对象,ServletContext对象、request对象,response对象 从图中我们可以知道这几个对象之间的联系!...一、ServletConfig对象 1.1、获取ServletConfig对象   1)使用初始化方法获得一个ServletConfig对象 ?   ...2)通过继承父类(GenericServlet)的方法得到一个ServletConfig对象    ServletConfig config = this.getServletConfig(); 1.2...、ServletConfig对象作用 ?   ...注意:在上面我们所分析的源码过程中,我们就知道,其实可以不用先获得ServletConfig,然后在获取其各种参数,可以直接使用其方法,比如上面我们用的ServletConfig().getServletName

88660

javax顶层接口分析

此接口中的方法有以下几个: public void init(ServletConfig config) throws ServletException; public ServletConfig getServletConfig...2.ServletConfig接口分析 此接口为Servlet配置抽象接口,定义了获取Servlet信息的相关接口,接口列表如下: //获取Servlet名称,即是web.xml中配置的servlet-name...此类中维护了一个ServletConfig变量,定义方式如下: private transient ServletConfig config; 添加transient修饰的作用:序列化的时候不包含此字段...= config; this.init(); } init方法是由Servletr容器调用,因此,web.xml中Servlet配置转化为ServletConfig的工作因该是由容器完成的。...其中ServletConfig接口的方法实现方式基本如下: public String getServletName() { ServletConfig sc = getServletConfig

53930

Servlet API 架构详解Servlet、GenericServlet、HttpServletServletConfigServletContext

(稍后会介绍servletConfig接口)的实例,然后调用servlet接口的init方法并且传入一个servletconfig实例,完成servlet的初始化。...的配置产生一个servletconfig的对象,随后调用servlet的接口的init方法,并且将产生的servletconfig的对象当作参数传入。...servletconfig的实例 GenericServlet也包括了Servlet與ServletConfig所定義方法的簡單實作,實作內容主要是透過ServletConfig來取得一些相關資訊,例如...的信息,而不用意识到servletconfig的存在。...但实际上,当整个Web应用程序加载进入Web容器之后,容器会生成一个ServletContext对象作为整个应用程序的代表,并设定给ServletConfig,你只要通过调用ServletConfig

65521

Servlet 体系结构

为何要设计成这样呢 Servlet 顶层类关联图 从上图可以看出 Servlet 规范就是基于这几个类运转的,与 Servlet 主动关联三个类 ServletConfig、ServletRequest...仔细查看 ServletConfig 接口中声明的方法,发现都是为了获取这个 Servlet 的一些配置属性,而这些配置属性可能在 Servlet 运行时被用到。...,它们通常都是作为运输工具来传递交互结果 ServletConfig 是在 Servlet init 时由容器传过来的,那么 ServletConfig 到底是个什么对象呢?...ServletConfig,ServletContext在 Tomcat 容器中的类关系 可以看出 StandardWrapper 和 StandardWrapperFacade 都实现了 ServletConfig...所以传给 Servlet 的是 StandardWrapperFacade 对象,它能够保证从 StandardWrapper 中拿到 ServletConfig 所规定的数据,而又不把 ServletConfig

79480
领券