当容器调用部署描述符(web.xml) [英] when container call deployment descriptor (web.xml)

查看:30
本文介绍了当容器调用部署描述符(web.xml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,每当一个 servlet 请求到来时,servlet 容器首先会检查 web.xml 文件中的 url 和相应的 servlet 类.这很好,但混乱随之而来.假设我正在使用 load-on-startup 属性.所以,servlet 应该在第一次调用之前准备好.在这种情况下,容器需要 servlet Config 对象来使 servlet 工作.但是同样在 web.xml 文件中定义了 servlet 的 load-on-start up 和 init-parameter.那么当容器使用 web.xml 时?(当使用 load-on-startup 属性时,容器显然不能等待第一次调用,容器必须再次读取 web.xml 文件以了解该属性是否与任何 servlet 一起使用.)

We know that whenever a request for a servlet comes, servlet container will first check web.xml file for url and corresponding servlet classes. This is fine, But the confusion comes after that. Suppose I am using load-on-startup property. SO, the servlet should be ready before first call comes in. In that case container need servlet Config object to make servlet in work. But again load-on-start up and init-parameter for servlet is defined in web.xml file. So when exactly container uses web.xml?( when load-on-startup property is used then container can not obviously wait for first call, again container has to read web.xml file to know whether that property is used with any servlet.)

如果有人能解决我的困惑会更好.如果可能,请提供一些可靠的链接.

It will be better if some one can clear my confusion. Please provide some dependable link also if possible.

推荐答案

加载和实例化:

servlet 容器负责加载和实例化 servlet.加载和实例化可以在容器启动时发生,也可以延迟到容器确定需要 servlet 来为请求提供服务.

The servlet container is responsible for loading and instantiating servlets. The loading and instantiation can occur when the container is started, or delayed until the container determines the servlet is needed to service a request.

当 servlet 引擎启动时,需要的 servlet 类必须由 servlet 容器定位.servlet 容器使用普通的 Java 类加载工具加载 servlet 类.加载可能来自本地文件系统、远程文件系统或其他网络服务.由于 servlet 是在 web.xml 中声明的,这个文件在容器启动期间被容器加载和读取.

When the servlet engine is started, needed servlet classes must be located by the servlet container. The servlet container loads the servlet class using normal Java class loading facilities. The loading may be from a local file system, a remote file system, or other network services. And as the servlets are declared in the web.xml, this file is loaded and read by the container during container startup.

初始化:

servlet对象实例化后,容器必须先初始化servlet它可以处理来自客户端的请求.容器通过使用实现 ServletConfig 接口的唯一(每个 servlet 声明)对象调用 Servlet 接口的 init 方法来初始化 servlet 实例.

After the servlet object is instantiated, the container must initialize the servlet before it can handle requests from clients.The container initializes the servlet instance by calling the init method of the Servlet interface with a unique (per servlet declaration) object implementing the ServletConfig interface.

参考:JSR-000315 JavaTM Servlet 3.0

这篇关于当容器调用部署描述符(web.xml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆