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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:17:53+00:00 2026-05-18T08:17:53+00:00

any comments on my code on allowing user to download file. if(fileObject !=null) response.setHeader(Content-disposition,

  • 0

any comments on my code on allowing user to download file.

if(fileObject !=null)
response.setHeader("Content-disposition", "attachment; filename=\""+fileObject.getFilename()+"\"");
response.setContentType(fileObject.getFiletype());
response.setContentLength((int)fileObject.getFilesize().intValue());
try {
 if(response !=null && response.getOutputStream() !=null &&fileObject!=null && fileObject.getBinData() !=null ){
    OutputStream out = response.getOutputStream();
    out.write(fileObject.getBinData());
 }


} catch (IOException e) {
    throw new ApplicationRuntimeException(e);
}

most of the time, i dont get below error. but once and a while, i get error

29 Nov 2010 10:50:41,925 WARN [http-2020-2] - Unable to present exception page: getOutputStream() has already been called for this response
java.lang.IllegalStateException: getOutputStream() has already been called for this response
 at org.apache.catalina.connector.Response.getWriter(Response.java:610)
  • 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-18T08:17:53+00:00Added an answer on May 18, 2026 at 8:17 am

    The exception message is clear:

    Unable to present exception page: getOutputStream() has already been called for this response
    java.lang.IllegalStateException: getOutputStream() has already been called for this response
    at org.apache.catalina.connector.Response.getWriter(Response.java:610)

    An IOException was been thrown and you’re rethrowing it as a custom exception which forced the servletcontainer to show the exception page which will use getWriter() for this. You should in fact let any IOException go because that’s usually a point of no return.

    An IOException can for example be thrown during the job when the client aborted the request. The best practice is to not catch IOException on the Servlet API yourself. It’s already declared in throws clause of the servlet methods.

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        FileObject fileObject = getItSomehow();
        if (fileObject != null && fileObject.getBinData() != null) {
            response.setHeader("Content-disposition", "attachment; filename=\"" + fileObject.getFilename() + "\"");
            response.setContentType(fileObject.getFiletype());
            response.setContentLength((int)fileObject.getFilesize().intValue());
            response.getOutputStream().write(fileObject.getBinData());
        } else {
            // ???
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an executable that accepts certain command line arguments. Any user on the
i have the folowing code: window.document.getElementById(bufferTopic).innerHTML = <img src='einstein/einstein.png' width='800' height='600'><script type='text/javascript' language='javascript'>alert('test');</script> i
I have a line of code in Matlab that reads: output = find(input); where
My method loads a list of countries(code, name) into the database, but before that
After the parse, I would like to remove dangerous code and write it out
I got a problem with tables in LaTeX. I am using a pre-defined format
Hey guys, first off I played around with shortcodes, but they aren't working. I
We are currently looking for ways to help the non-programming members of the sysadmin
I've been experimenting with genetic algorithms as of late and now I'd like to

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.