Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:28:33+00:00 2026-05-30T11:28:33+00:00

I am having trouble in returning compressed response (GZip) from my Java Servlet, to

  • 0

I am having trouble in returning compressed response (GZip) from my Java Servlet, to a JSP.

Flow :

  1. Request comes to java servlet
  2. Process the request, and create a JSON object, with the response
  3. Convert the JSON object to string
  4. Compress the response string with GZip
  5. The compressed response string is set as attribute in the request object and control passed to JSP
  6. In the JSP, the response string (compressed) is printed on screen

Precautions :

  1. Request object has “Accepting-Encoding” set with “gzip”
  2. Response header has “Content-Encoding” set to “gzip”
  3. Response content type is set to “application/json”
  4. Response character encoding is set to “ISO-8859-1”

Result :

  1. Firefox shows “Content Encoding Error”
  2. Chrome shows “Error 330 (net::ERR_CONTENT_DECODING_FAILED): Unknown error.”

Can anyone help point me out, in the right direction please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:28:34+00:00Added an answer on May 30, 2026 at 11:28 am

    The compressed response string is set as attribute in the request object and control passed to JSP

    You shouldn’t have forwarded a JSON response to a JSP. You should have printed the JSON plain to the response and have the JavaScript/Ajax code in your JSP Android app to call the URL of the servlet which returns the JSON. See also How to use Servlets and Ajax?.

    As to the GZIP compression, you shouldn’t do it yourself. Let the server do itself.

    Fix your code to remove all manual attempts to compress the response, it should end up to basically look like this:

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String json = createItSomehow();
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(json);
    }
    

    That’s all, if you let your Android app call the URL of the servlet, it’ll retrieve the JSON string.

    Finally edit the server configuration to turn on automatic GZIP compression. In case of for example Tomcat, that would be a matter of adding compression="on" to the <Connector> element in Tomcat’s /conf/server.xml file:

    <Connector ... compression="on">
    

    As per the documentation, the compressable mime types defaults to text/html,text/xml,text/plain. You can configure this to add application/json.

    <Connector ... compression="on" compressableMimeType="text/html,text/xml,text/plain,application/json">
    

    Unrelated to the concrete problem, the response character encoding must be set to UTF-8 which is as per the JSON specification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble returning arrays from a custom method. It compiles fine but I
I'm having trouble getting a response back from a Jquery ajax call... (It's a
I am having trouble returning data from my sql-server database to an aspx page
I'm having trouble returning data from my controller using an ajax post function. What
I am having some trouble returning matrix data from one method to the main
I'm having trouble developing a standard for returning data from user functions passed and
I'm having some trouble returning multiple values in this program that calculates min, max,
Im having trouble reading from a CSV file final String DELIMITER = ,; Scanner
I am having trouble with my queries not returning any results. There are no
I am a total C++ noob, and I am having some trouble returning an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.