小编典典

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

tomcat

我正在使用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”/>

阅读 314

收藏
2020-06-16

共1个答案

小编典典

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

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

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

2020-06-16