JSP gzip输出流 [英] JSP gzip output stream
问题描述
我知道我可以使用类似的东西gzip输出流.
I know I can gzip the output stream by using something like..
OutputStream outA = response.getOutputStream();
outWriter = new PrintWriter(new GZIPOutputStream(outA), false);
response.setHeader("Content-Encoding", "gzip");
outWriter.println(.....);
outWriter.close();
在JSP中,但是可以将其编写为:
in a JSP, but is it possible to write it as:
OutputStream outA = response.getOutputStream();
outWriter = new PrintWriter(new GZIPOutputStream(outA), false);
response.setHeader("Content-Encoding", "gzip");
%>
...
我知道这是在PHP中完成的,例如,在刷新输出缓冲区之前捕获其输出缓冲区,对缓冲区进行gzip处理,然后最终将其写入.
I know this is done in PHP for example by capturing the output buffer before it is flushed, gzipping the buffer, and then finally writing it.
但是在JSP中有可能吗?
But is it possible in a JSP?
推荐答案
此Java代码不属于JSP.
This Java code doesn't belong in a JSP.
如果要对由JSP生成的HTML代码进行gzip压缩,则需要在appserver级别对其进行配置.在JBoss(和Tomcat)中,需要将/server.xml
中<Connector>
元素的compression
属性设置为on
.
If your intent is to gzip the HTML code generated by JSP, then you need to configure it at appserver level. In JBoss (and Tomcat) you need to set the compression
attribute of the <Connector>
element in /server.xml
to on
.
<Connector compression="on">
仅此而已.默认情况下,它将应用于所有text/*
响应(HTML/CSS/JS).
That's all. It'll be by default applied on all text/*
responses (HTML/CSS/JS).
- Tomcat 6.0 HTTP Connector configuration reference
- Web application performance tips and tricks
这篇关于JSP gzip输出流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!