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. Servlet中init-param与context-param的区别

    web.xml文件中Servlet中配置如下: <servlet> <servlet-name>loginServlet</servlet-name> <se ...

  2. JAVA 数组的常用操作

    目录: 声明数组: 初始化数组: 查看数组长度: 遍历数组: int数组转成string数组: 从array中创建arraylist: 数组中是否包含某一个值: 将数组转成set集合: 将数组转成li ...

  3. 3-C++程序的结构1.2

    对象的生存周期 可以分为静态生存周期和动态生存周期 1.静态生存周期 如果对象的生存期与程序的运行期相同,我们称它具有静态生存期.在文件作用域中声明的对象都具有静态生存期的.如果要在函数的块中声明具有 ...

  4. LeetCode: 575 Distribute Candies(easy)

    题目: Given an integer array with even length, where different numbers in this array represent differe ...

  5. [OpenGL]配置GLFW(超详细)

    注:本文可转载,转载请著名出处:http://www.cnblogs.com/collectionne/p/6937644.html.本文还会修改,如果不在博客园(cnblogs)发现本文,建议访问上 ...

  6. CodeForces 723F【DFS瞎搞】

    题意: 给你一幅图,你要用这些边构造一个树, s和t两个节点的度数不能超过ds dt 而且图是保证没有环 思路: 树的性质是:无环(已经保证),无向(保证),连通(还要判断) 首先把S,T点从图里剥离 ...

  7. Educational Codeforces Round 19 A, B, C, E(xjb)

    题目链接:http://codeforces.com/contest/797 A题 题意:给出两个数n, k,问能不能将n分解成k个因子相乘的形式,不能输出-1,能则输出其因子: 思路:将n质因分解, ...

  8. Codevs 1523 地精部落

    1523 地精部落 省队选拔赛  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master 题解       题目描述 Description 传说很久以前,大地上居住 ...

  9. IT兄弟连 JavaWeb教程 JSP经典面试题

    1.JSP标准提供了三种独立的向JSP添加Java代码的技术,请列举. <% %>JSP程序代码块,内部可以直接嵌入Java代码. <%! %>JSP声明区,内部可以声明变量和 ...

  10. 笔记-JavaWeb学习之旅5

    CP30的演示 package cn.itcast.datasourcejdbc; import com.mchange.v2.c3p0.ComboPooledDataSource; import j ...