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 6579007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:50:38+00:00 2026-05-25T15:50:38+00:00

There is an ajax js function which send request & get response and it

  • 0

There is an ajax js function which send request & get response and it often get successful but i smell somthing messy when i checked using firbug. please take a look.
when request success: ajaxRequest.getResponseHeader('content-Length'); returns null
But in actual the content-length is in digits. following is the firbug console output

HeadersResponseXML

Server  Apache-Coyote/1.1
Content-Type    text/xml
Transfer-Encoding   chunked
Date    Thu, 15 Sep 2011 07:23:36 GMT

when request failed : it returns 0 (zero),and it’s correct.
Headers
Server Apache-Coyote/1.1
Content-Length 0
Date Thu, 15 Sep 2011 07:23:53 GMT

I don’t see any content-length in response header when it succeed why? please compare success & failure firebug console output. How can I get actual content-length.

  • 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-25T15:50:39+00:00Added an answer on May 25, 2026 at 3:50 pm

    Read the javadoc of the doGet() (or doPost()) method of HttpServlet:

    …

    Where possible, set the Content-Length header (with the ServletResponse.setContentLength(int) method), to allow the servlet container to use a persistent connection to return its response to the client, improving performance. The content length is automatically set if the entire response fits inside the response buffer.

    When using HTTP 1.1 chunked encoding (which means that the response has a Transfer-Encoding header), do not set the Content-Length header.

    …

    In other words, if you do not set the content length yourself inside your servlet and the response body is larger than the default response buffer size (often 2KB, configureable in server settings), then the servlet will send it using chunked encoding (technically, to prevent memory problems if it had to buffer large responses entirely in memory before being able to set the content length).

    If you really need the content length in the response header for some reason, then you need to buffer the entire response body yourself before writing. E.g.

    StringBuilder builder = new StringBuilder();
    builder.append(someXml);
    // ...
    
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    response.setContentLength(builder.length());
    response.getWriter().write(builder.toString());
    

    You only need to keep in mind that this can be a potential memory hog whenever the response body is extraordinary large.

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

Sidebar

Related Questions

There are websites that when I open specific ajax request on browser, I get
I have a situation where I send jquery ajax post request but in my
In jQuery ajax function there is xhr option. Does someone know more details, usability
Is there any free ajax uploading control which can give black-screen on the page
I see there is full ajax mode but I wanted to see if there
Is there an ASP.NET AJAX framework other than just using UpdatePanel & Friends or
I'm designing a template creation tool, which uses a jQuery Ajax request that posts
I am using dojo and ajax to send a time stamp to PHP, which
If there anyway allows AJAX between two own domains without proxy hacking, JSONP, Flash
Is there a norm for AJAX security? When making an XMLHttpRequest, if querying 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.