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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:08:51+00:00 2026-05-14T18:08:51+00:00

I have a webpage that makes an ajax call to get some data. That

  • 0

I have a webpage that makes an ajax call to get some data. That data takes a long time to calculate, so what I did was the first ajax server call returns “loading…” and then the thread goes on to calculate the data and store it in a cache.
meanwhile the client javascript checks back every few seconds with another ajax call to see if the cache has been loaded yet.

Here’s my problem, and it might not be a problem. After the initial ajax to the server call, I do a

...getServletContext().getRequestDispatcher(jsppath).include(request, response);

then I use that thread to do the calculations. I don’t mind tying up the webserver thread with this, but I want the browser to get the response and not wait for the server to close the socket.

I can’t tell if the server is closing the socket after the include, but I’m guessing it’s not.

So how can I forcibly close the stream after I’ve written out my response, before starting my long calculations?

I tried

o = response.getOutputStream();
o.close();

but I get an illegal state exception saying that the output stream has already been gotten (presumably by the jsp I’m including)

So my qestions:

  1. is the webserver closing the socket (I’m guessing not, because you could always include another jsp)

  2. if it is as I assume not closing the socket, how do I do that?

  • 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-14T18:08:51+00:00Added an answer on May 14, 2026 at 6:08 pm

    I don’t see how you can even close the OutputStream if the calculation is still going on in the same thread.

    You need to start the calculation in a new thread and just return from the Servlet and the response will be sent back automatically.

    If you really need to close the writer, do this,

      response.getWriter().close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first forray into ajax webpages is causing me some problems. My basic structure
After spending many hours poking around trying to get an ASP .NET AJAX proxy
I have a web page that I need to check the server for an
While I was trying to refresh page contents dynamically using Ajax/JQuery, I have learned
I have a really strange problem that I can't explain and fix, it is
I'm making a web application using PHP in where I have a form that
I'm wondering about this: I have a simple facebook-connect app that will only show
I honestly have no idea if this question has been asked before, or something
I have a 'tabbed' style web page where once the page loads each tab
So I've been working recently on a script to obfuscate client-side code for protecting

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.