JSP gzip 输出流
我知道我可以通过在JSP中使用类似..的东西来gzip输出流
OutputStream outA = response.getOutputStream();
outWriter = new PrintWriter(new GZIPOutputStream(outA), false);
response.setHeader("Content-Encoding", "gzip");
outWriter.println(.....);
outWriter.close();
,但是是否可以将其写为:
OutputStream outA = response.getOutputStream(); outWriter = new PrintWriter(new GZIPOutputStream(outA), false); response.setHeader("Content-Encoding", "gzip"); %> ...
我知道这是在PHP中完成的,例如通过在刷新之前捕获输出缓冲区,gzipping缓冲区,然后最后写下来。
但在 JSP 中可能吗?
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();
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"); %> ...
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.
But is it possible in a JSP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此 Java 代码不属于 JSP。
如果您的目的是压缩 JSP 生成的 HTML 代码,那么您需要在应用程序服务器级别对其进行配置。在 JBoss(和 Tomcat)中,您需要将
/server.xml
中
元素的compression
属性设置为上。
就这样。默认情况下,它将应用于所有
text/*
响应 (HTML/CSS/JS)。另请参阅:
This Java code doesn't belong in a JSP.
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
toon
.That's all. It'll be by default applied on all
text/*
responses (HTML/CSS/JS).See also: