我使用的是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”/>发布于 2013-03-09 08:06:51
编辑:根据来自pieroxy的注释将属性compressableMimeType更新为compressibleMimeType
我发现您可以像这样设置属性:
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");我猜这也适用于您需要设置的其他连接器属性。
https://stackoverflow.com/questions/15304921
复制相似问题