As a Response to an Ajax request, I would like to send compressed i.e. gzipped JSON from my Java program. I know, I would need to set the Content-Encoding in the Response Header to gzip, but is that all I need to do?
You would also need to make sure that a) your client (browser or app) accepts this gzip encoding and can deal with it b) your server (container for your java application) is configured to send responses gzipped by default. If the server is configured to send gzipped responses, then the content-type header will most likely be set by the server itself.
Thanks guys for your inputs. I used the following to make it work.
In my application web.xml, added the following filter:
<filter>
<filter-name>GZipFilter</filter-name>
<filter-class> org.mortbay.servlet.GzipFilter</filter-class>
<init-param>
<param-name>mimeTypes</param-name>
<param-value>application/json</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>GZipFilter</filter-name>
<url-pattern>*.data</url-pattern>
</filter-mapping>
And in the servlet.xml added the following bean property to DataViewController bean.
<beans:property name="contentType" value="application/json" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With