Glassfish 3 - gzip 压缩不适用于 .jsp
请观看这段简短的视频,其中详细介绍了我的问题:http://youtu. be/uAza4m3fxpY?hd=1
我有一台运行 Netbeans Web 项目的 Glassfish 3.1 服务器。 我有一个非常简单的 .jsp 文件,内容类型设置为“text/html”,正文中有一大段虚拟文本。它看起来像这样:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gzip Test</title>
</head>
<body>
<h1>Gzip compsression test</h1>
<p>****LOTS OF DUMMY TEXT***</p>
</body>
</html>
在 Glassfish 管理中,我为 HTTP 侦听器强制启用了 gzip 压缩(如本指南中所述:http://www.vikasing.com/2010/01/enable-gzip-compression-on-glassfish-v3.html)
当在 Firefox 中加载页面并查看响应标头时,我希望看到 Content-Encoding: gzip
,但它不存在。
为什么内容没有被 Gzip 压缩?
Please watch this short video which shows my problem in detail: http://youtu.be/uAza4m3fxpY?hd=1
I have a Glassfish 3.1 server running a Netbeans Web Project.
I have a very simple .jsp file with content type set to 'text/html' and a large paragraph of dummy text in the body. It looks like this:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gzip Test</title>
</head>
<body>
<h1>Gzip compsression test</h1>
<p>****LOTS OF DUMMY TEXT***</p>
</body>
</html>
In Glassfish admin, I have forced-enabled gzip compression for the HTTP listener (as described in this guide: http://www.vikasing.com/2010/01/enable-gzip-compression-on-glassfish-v3.html)
When load the page in Firefox and look at the response header, I would expect to see Content-Encoding: gzip
, but it's not there.
Why is the content not being Gzipped?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现这是 Glassfish 3.1 中的一个错误。它不会使用
,
字符属性分割accept-encoding
标头。例如,如果您将 Firefox 的accept-encoding
标头设置为:gzip, deflate
它不会对内容进行 gzip 压缩,因为逗号搞砸了,但如果您将其设置为 < code>gzip 那么它就会被服务器压缩,因为没有逗号可以阻塞。显然这个问题已经在 Glassfish 3.1.1 中得到修复,但我还没有测试过。请参阅: http:// /www.java.net/forum/topic/glassfish/glassfish/gzip-compression-glassfish-3-doesnt-work?force=899 了解更多详细信息。I've discovered that this is a bug in Glassfish 3.1. It does not property split the
accept-encoding
header using the,
character. For example, if you set firefox'saccept-encoding
header to:gzip, deflate
it will not gzip the content because the comma screws it up, but if you set it togzip
then it does get gzipped by the server because there is no comma to choke on. Apparently this has been fixed in Glassfish 3.1.1 but I have not tested it yet. See: http://www.java.net/forum/topic/glassfish/glassfish/gzip-compression-glassfish-3-doesnt-work?force=899 for more details.感谢您的视频。
我记得这是在 Glassfish 3.0 作为 FishCAT 的一部分发布之前出现的。
我认为您遇到的问题是因为您只设置了一个侦听器“http-listener-1”,并且还需要设置“http-listener-2”。
(也许你这样做了,但没有在视频中展示?)
Thanks for the video.
I remember this came up before Glassfish 3.0 was released as a part of FishCAT.
I think the problem you are having is because you are only setting the one listener 'http-listener-1' and you need to set 'http-listener-2' as well.
(perhaps you did this, but did not show it in the video ?)
Glassfish 3.1.2 甚至 4.0 Beta 中也存在同样的错误 - 看起来 gzip 压缩已经变得完全有问题。即使 firefox 的接受编码设置为仅 gzip,它也不起作用。
您可能正在使用 Google 的 CompressionFilter,但它很难使用,因为它使用了许多依赖项。
The same bug in Glassfish 3.1.2 and even 4.0 Beta - it looks like gzip compression has become completely buggy. Even if accept-encoding of firefox is set to solely gzip it doesn't work.
You might be using CompressionFilter from Google, but it is quitely difficult to use as it use a number of dependencies.
我对 glassfish 3.1.2.2 和 gzip 也有同样的问题。
1.0 版本中对 HTTP 请求的响应未压缩。您必须使用 HTTP 1.1 发送请求,才能从 glassfish 服务器获取压缩后的响应。
此外,您必须在 http 请求中添加标头 “Accept-Encoding: gzip”。
I've got the same issues with glassfish 3.1.2.2 and gzip.
Responses to HTTP requests in version 1.0 are not compressed. You must send your requests in HTTP 1.1 to get gzipped responses from your glassfish server.
More over, you must add the header "Accept-Encoding: gzip" in your http requests.