tomcat context配置

来源:互联网 发布:矢量软件coreldraw 编辑:程序博客网 时间:2024/06/16 18:17


The Context element represents a web application, which is run within a particular virtual host. Each webapplication is based on a Web Application Archive (WAR) file, or a corresponding directory containing thecorresponding unpacked contents, as described in the Servlet Specification(version 2.2 or later). For more information about web application archives,you can download the Servlet Specification,and review the Tomcat Application Developer's Guide.

Theweb application used to process each HTTP request is selected by Catalina basedon matching thelongest possible prefix[c1] of the Request URI against the context path of each defined Context.Once selected, that Context will select an appropriate servlet to process theincoming request, according to the servlet mappings defined by the webapplication deployment.

Youmay define as many Context elementsas you wish. Each such Context MUST have a unique context name within a virtualhost. The context path does not need to be unique (see paralleldeployment below). In addition, a Contextmust be present with a context path equal to a zero-length string. This Contextbecomes the default webapplication for this virtual host, and is used to process all requests that donot match any other Context's context path.

 

context的参数:

crossContext="true" ,是允许应用通过ServletContext.getContext()去拿到一个通往别的应用request dispatcher。当然了,这种方法无法跨越现在Tomcat支持的虚拟主机界限。也就是说,能够穿透访问的,必须是和当前应用在一个<Host>之中的应用。

privileged="true" 意味着 Tomcat自身的应用,比如·Tomcat Manager ,可以被当前这个应用访问。根据官方文档的解释,这个机理是改变应用的类加载器为Server class loader。我想,这种改变,会令应用程序发现Tomcat本身的类,都能够从应用自己的类加载器上寻找到。从而实现对Tomcat自身应用程序方法的调用。

path docBase不用多说,都要指定这二个属性的。其中docBase可以是目录也可以是结构完整的.war文件。

reloadable="true" 意味着 Tomcat将提供对应用类路径(/WEB-INF/classes//WEB-INF/lib/)的监测。当这里边有内容改变并且其类已经被爪哇虚拟机(JVM)加载的时候,Tomcat可以自行重新加载此类。不过此功能对Tomcat的稳定服务影响不小,调试环境可以使用,生产环境还是算了吧——当然,这只是我的个人建议。

unpackWAR 就如字面意思,unpackWAR="true"意味着 Tomcat会保存 .war包的解压结果,然后直接对解压结果进行运行。我个人认为,考虑到爪哇虚拟机的类加载机制,每个类都仅加载一回,但是页面内容却没有类似的有效缓存,所以.war还是解压执行的比较好。而且日志也将造成unpackWAR="false"形同灾难。

cachingAllowed="true" 意味着开启了Tomcat7的静态缓存功能。静态文件包括JavaScript程序、图片声音等允许网络访问的文件以及HTML页面。

cacheMaxSize 是静态缓存功能缓冲区大小的设定。单位是MB,也就是 1024KB。例子中设为 1024,意味着 1GB



0 0
原创粉丝点击