以编程方式启用GZIP Tomcat 7(嵌入式)

问题描述 投票:1回答:1

我正在使用Tomcat7(嵌入式)

这样的事情...

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中(我没有!)

<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”/>
tomcat tomcat7 embedded-tomcat-7
1个回答
4
投票

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

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");

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

© www.soinside.com 2019 - 2024. All rights reserved.