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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:34:07+00:00 2026-05-20T06:34:07+00:00

Do I need to flush the OutputStream from the HttpServletResponse? I already saw from

  • 0

Do I need to “flush” the OutputStream from the HttpServletResponse?

I already saw from to Should I close the servlet outputstream? that I don’t need to close it, but it’s not clear if I need to flush it. Should I expect it from the container as well?

protected void doGet(HttpServletRequest request, HttpServletResponse response) 
   throws ServletException, IOException {
   byte[] response = getResponse();
   String responseType = getResponseType();

   response.setContentLength(response.length);
   response.setContentType(responseType);
   response.getOutputStream().write(response);
   response.getOutputStream().flush(); // yes/no/why?
}
  • 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-20T06:34:08+00:00Added an answer on May 20, 2026 at 6:34 am

    You don’t need to. The servletcontainer will flush and close it for you. The close by the way already implicitly calls flush.

    See also chapter 5.6 of Servlet 3.1 specification:

    5.6 Closure of Response Object

    When a response is closed, the container must immediately flush all remaining
    content in the response buffer to the client. The following events indicate that the servlet has satisfied the request and that the response object is to be closed:

    • The termination of the service method of the servlet.
    • The amount of content specified in the setContentLength or
      setContentLengthLong method of the response has been greater than zero and
      has been written to the response.
    • The sendError method is called.
    • The sendRedirect method is called.
    • The complete method on AsyncContext is called.

    Calling flush while still running the servlet’s service is usually only beneficial when you have multiple writers on the same stream and you want to switch of the writer (e.g. file with mixed binary/character data), or when you want to keep the stream pointer open for an uncertain time (e.g. a logfile).

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

Sidebar

Related Questions

byte[] data = (byte[])opBinding.execute(); PrintWriter out = new PrintWriter(outputStream); out.println(data); out.flush(); out.close(); but instead
I need to back my database, but when trying to flush the tables before
I need to flush the index periodically.that's mean that the index will be regularly
With this code i am able to render a image from a servlet ,But
I am in need of a Flash swf that is capable of loading PCM
We need send h264 from flash to Wowza and after to vlc by RTSP
I need to create a flash projector application which can be interacted with, but
I need to call some jQuery .load() function from flash. i Use this: import
I need to use the tcp socket connection to get the data from a
I want to write System.out messages to another OutputStream , but I still want

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.