• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to compress jsp?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
In servlet, we can compress the output to speed up the web page loading.
In JSP, how can we do this?
Thanks!
Michael Deng

Example in Servlets:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
...
try {
GZIPOutputStream gzos =
new GZIPOutputStream(response.getOutputStream());
gzos.write(sb.toString().getBytes());
gzos.close();
} catch(IOException ie) {
// handle the error here
...
}
...
} // end doGet
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it's probably easiest to install a zip utility (like modgzip for Apache) on your web server so that all of your content is zipped regardless of its origin...
You could do what you're doing in Servlets in a JSP, too, but the other option is probably far easier.
Kyle
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I used this code in my program. but when i used GZipOutputStream. It displayed the download box on the client machine.
Plz help me how to send the fast output to the client.
Thanks in advance,
Rajesh
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,
I think Kyle suggestion is the best. However if you don't/can't use Apache as a web front end, have a look at your web/application server console to see if your can enable this behaviour.
If not, depending on the version of servlet engine you're using, you might be able to use a Filter servlet to do the compression. This provides better encapsulation of the feature.
Anyway, before performing gzip compression, you must ensure the client web browser supports the gzip compression.
Try to find the word gzip in the Accept-Encoding line in the request headers. If found, the client accepts gzip.
In that case, you can compress your output using the GZIPOutputStream, but do not forget to tell the client you are sending him a compressed stream by setting gzip in the Content-Encoding line of the server's response header.
Cheers
 
Michael Deng
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your guys' reply.
Do you know where can I download modgzip? Is it free?
I tried to search it in google, but, it seems I counldn't download it anymore.
I have another question, if my jsps contain lots of gif, will modgzip put all the images in one zip file at the same time?
Cheers!
Michael
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic