Reputation: 4316
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?
Upvotes: 3
Views: 4590
Reputation: 1108722
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
to on
.
<Connector compression="on">
That's all. It'll be by default applied on all text/*
responses (HTML/CSS/JS).
Upvotes: 7