以编程方式启用 GZIP Tomcat 7(嵌入式) [英] Programmatically enable GZIP Tomcat 7 (embedded)

查看:22
本文介绍了以编程方式启用 GZIP Tomcat 7(嵌入式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Tomcat7(嵌入式)

I am using Tomcat7 (embedded)

这样的东西...

String APP_DIR = "ROOT";
Tomcat current = new Tomcat();
File file = new File(APP_DIR);
if (file.isDirectory() && file.canRead()) {
    ctx = current.addWebapp(null, "", file.getAbsolutePath());
    ctx.setSessionCookiePathUsesTrailingSlash(false);
}
current.start();
ctx.addServletMapping("*.pdf", "jsp", true);

我启用了 *.pdf 到 jsp servlet 的映射(我在使用 IE 时遇到了一些问题)有没有办法用这个配置启用 GZIP(我没有 web.xml,但如果需要,我可以添加以使其工作)到目前为止,我只发现我需要将它添加到我的 web.xml(我没有!)

I have enabled the *.pdf mapping to jsp servlet (some issue I had with IE) is there a way to enable GZIP with this config (I have no web.xml, but if needed I could add to make it work) So far I have only found that I need to add this to my web.xml (which I don't have!)

<Connector port="8080″ maxHttpHeaderSize="8192″
maxThreads="150″ minSpareThreads="25″ maxSpareThreads="75″
enableLookups="false" redirectPort="8443″ acceptCount="100″
connectionTimeout="20000″ disableUploadTimeout="true"
compression="on"
compressionMinSize="2048″
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"/>

推荐答案

我发现你可以这样设置属性:

I found that you can setup the properties like this:

Tomcat current = new Tomcat();
Connector c = this.current.getConnector();
c.setProperty("compression", "on");
c.setProperty("compressionMinSize", "1024");
c.setProperty("noCompressionUserAgents", "gozilla, traviata");
c.setProperty("compressableMimeType", "text/html,text/xml, text/css, application/json, application/javascript");

我想这也适用于您需要设置的其他连接器属性.

I guess that this also applies for other connector property that you need to set up.

这篇关于以编程方式启用 GZIP Tomcat 7(嵌入式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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