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

我已经启用了到 jsp servlet 的 *.pdf 映射(我在 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”/>
4

1 回答 1

4

编辑:compressableMimeType根据compressibleMimeType评论更新属性pieroxy

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

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

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

于 2013-03-09T00:06:51.060 回答