Servlet Context

Container Provider 负责提供ServletContext的实现.

A ServletContext is rooted at a known path within a Web server. For example, a

servlet context could be located at http://www.mycorp.com/catalog . All requests

that begin with the /catalog request path, known as the context path, are routed to

the Web application associated with the ServletContext .

在每一个容器中都有一个ServletContext, 但是当容器被部署在不同的JVM上时, 每一个JVM中有一个ServletContext

Configuration methods

增加了动态增加servlet, filter等函数.

ServletContext中也可以放置Attributes来和Servlet Container交互, 但是都是存在在一个JVM上的, 不可能跨JVM存在.

另外, 提供了一些对于配置的API, 主要是关于三者: Servlet, Filter ,ContextListener; 具体在编程时参考Javadoc

Context Attributes

所有绑定到同一个Context上的Servlet可以访问同样的一些attribute object. 事实上, 该类属性是被分配在JVM上的一块共享空间的, 如果需要在分布式的环境下使用, 则需要把这些属性放在session,或者是database,或者JavaBean中.

Resources

ServletContext访问静态资源的方法, 如下:

getResource
getResourceAsStream

两个函数都是先搜寻Context所在的根目录, 然后是WEB-INF/lib下面Jar包中的META-INF/resources目录, 但是搜寻Jar包下资源的顺序是不定的.但是对于动态资源如jsp, 则是不适用的, 需要根据分发请求来决定.

Multiple Hosts and ServletContexts

当多台服务器公用一个IP地址的时候, 会使用"virtual hosting", 而每一台host应该拥有独立的servlet context, 之间不能被共享.

Servlet Context的更多相关文章

  1. Spring的servlet context和application context

    Spring lets you define multiple contexts in a parent-child hierarchy. The applicationContext.xml def ...

  2. servlet context 和 servlet config

    servletConfig Servlet容器初始化一个servlet对象时,会为这个servlet对象创建一个servletConfig对象,该对象中包含了servlet的<init-para ...

  3. INFO Dispatcher:42 - Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.tempdir

    INFO Dispatcher:42 - Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax ...

  4. JavaWeb核心编程之(三.4)Servlet Context 配置

    ServletContextServlet引擎为每个Web应用程序都创建一个对应的ServletContext对象, ServletContext对象被包含在ServletConfig对象中, 调用S ...

  5. Java Servlet规范

    截自网址:http://blog.csdn.net/u010391029/article/details/46521051 JavaServlet Specification  Version 2.3 ...

  6. context元素大概解说

    Context元素代表一个web应用,运行在某个特定的虚拟主机上.如Servlet Specification 2.2或以后版本中描述的那样,每个web应用基于一个Web Application Ar ...

  7. Servlet 3特性:异步Servlet

    解异步Servlet之前,让我们试着理解为什么需要它.假设我们有一个Servlet需要很多的时间来处理,类似下面的内容: LongRunningServlet.java package com.jou ...

  8. What is the difference Apache (Http Server) and Tomcat (Servlet Container)

    The Apache Project The Apache Project is a collaborative software development effort. Its goal is to ...

  9. Context上下文对象(抄书的)

    Servlet上下文 ServletContext 上下文接口    ServletContext接口    每一个应用都有唯一的一个上下文对象,即为ServletContext对象    Servl ...

随机推荐

  1. error: templates may not be ‘virtual’

     模板函数不能是虚函数,原因如下:   首先呢,模板函数并不是函数,他需要特定的类型去实例化成为函数.你定义一个函数模板,是不生成任何函数的,只有当你用代码去调用它时,才会根据你的类型去实例化成为特定 ...

  2. POJ 1182 食物链 (破题)

    题意:中文题. 析:对POJ 真是无语,有的题用G++过不了,C++能过,有的题不写EOF(题目明明说就一组的数据的)不过,有的题写EOF也不过, 这个题就是写EOF就过不了... 这个题用的是加权并 ...

  3. python---socket与socketserver

    1.socket的方socket.getaddrinfo(host, port, family=0, type=0, proto=0, flags=0) #获取要连接的对端主机地址sk.bind(ad ...

  4. yarn 基础

    创建: 2019/04/06  安装 mac brew install yarn  升级 brew upgrade yarn 确认是否成功 yarn --version  初始化项目 yarn ini ...

  5. C#字符串判断

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  6. spring框架——依赖注入

    依赖注入:DI 又称控制反转:IoC 项目名字spring_DI 一.implement包中定义了两个接口Food和Person 1.接口Food package org.interfaces; pu ...

  7. 5本自然语言处理书单-附pdf

    文章发布于公号[数智物语] (ID:decision_engine),关注公号不错过每一篇干货. 自然语言处理(英语:Natural Language Processing,缩写作 NLP)是人工智能 ...

  8. unicode码表和标准下载 unicode官网

  9. ios 微信登录相关

    引入项目的文件 info.plist 添加内容 WXApi.registerApp(Config.wx.APP_ID,enableMTA: true)//注册微信api(在AppDelegate里面注 ...

  10. idea | 命名空间改过后重新导入项目方法

    file菜单-->Open-->找到项目中pom文件-->会提示as project 和as file-->选择as project,会自动生成idea所有相关的文件