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

  • Home
  • SEARCH
  • 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 7161989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:39:38+00:00 2026-05-28T13:39:38+00:00

I am writing a data transfer application using a servlet and would like to

  • 0

I am writing a data transfer application using a servlet and would like to be able to send an error response if a problem occurs after the servlet response has been written to. Is that possible?

My issue is that I will be sending large compressed csv files that are created from data read from a database. Everything is done with streams so it is possible that an error could occur in the creation of the csv file after the servlet response has been written to. I have seen it happen.

I’ve noticed that this is only a problem after the servlet OutputStream has been flushed. If it has not been flushed I can send an error response but not after. Since I am dealing with large amounts of data it is not feasible to send everything in one go.

  • 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-28T13:39:39+00:00Added an answer on May 28, 2026 at 1:39 pm

    I am writing a data transfer application using a servlet and would like to be able to send an error response if a problem occurs after the servlet response has been written to. Is that possible?

    Not from the server side on. The server cannot take the already flushed bytes back from the client. This is a point of no return. I assume that this concerns a different exception than IOException on the response’s Writer or OutputStream.

    If it were HTML (even though this is a poor practice; HTML belongs in JSP), you could print some JS code which forces a location change like so:

    try {
        writer.write(someHtml);
    } catch (SomeException e) {
        writer.write("<script>window.location = 'error.jsp';</script>");
        // ...
    }
    

    But this is not possible in non-HTML responses. You’d really need to buffer the entire response in memory or on (temp) disk beforehand. If buffering went flawlessly, then you can pipe it to the response again.

    try {
        processAndSaveInMemoryOrTempDiskFile(someData, byteArrayOrFileLocation);
    } catch (SomeException e) {
        throw new ServletException(e, "Processing some data failed.");
    }
    
    copyFromMemoryOrTempDiskToResponse(byteArrayOrFileLocation, writer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a client/server application in Java and I'm using TCP to transfer data
I'm writing a XUL application using JavaScript for the coding. I would like to
I am writing the data to the output browser using Response.write(some byte arrary) Response.ContentType
I would like to store some Application-Related Metadata for Files, and NTFS Alternate Data
I'm writing a mule application that implements some web services using Jersey. I'd like
I had problem to transfer data over TCP. So i was writing a UDP
My application is SL2 reading and writing data through an Entity Framework Model exposed
I am writing a Silverlight application that will be both reading and writing data
I'm writing a data structure in C# (a priority queue using a fibonacci heap
I'm currently writing a data access layer for an application. The access layer makes

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.