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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:42:37+00:00 2026-06-09T23:42:37+00:00

I have a tomcat6 servlet that manages incoming HttpPosts this way: public void doPost(HttpServletRequest

  • 0

I have a tomcat6 servlet that manages incoming HttpPosts this way:

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        if (request.getParameter("cmd") != null) {
        eventPool.addEvent(new CommandEvent(new String[] { request.getParameter("cmd"),
                request.getParameter("json") }, response));
    }
}

The request will now be processed. When this is done, I want to write the result to the requesting client this way:

protected void sendResponse(HttpServletResponse httpResponse, String content){
    try {
        httpResponse.getWriter().println(CMD + "#" + content);
        httpResponse.getWriter().close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

But it fails to flush and I get a NullPointerException because the HttpResponse was already closed.

How can I prevent the HttpResponse from flushing before I want it to?

  • 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-06-09T23:42:39+00:00Added an answer on June 9, 2026 at 11:42 pm

    You’ll need to use Tomcat 7 (or any other container that supports Servlet 3.0 onwards) to use that style of programming. Look at the asynchronous request processing parts of the Servlet 3.0 specification.

    Prior to Servlet 3.0, request/response processing is synchronous. i.e. you cannot ‘park’ a request/response pair and then handle them later in a different thread. Pretty much as soon as your doPost() method exits, Tomcat will recycle the request and response objects ready to use them to handle a new request.

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

Sidebar

Related Questions

I have a servlet that handles a particular incoming request. We'll call it `UpdateUserStats'.
in the tomcat6 server I have a project that contains a servlet, I called
I have a java servlet that upon a request crunches on data and produces
I have a legacy Java servlet that is currently running in a Tomcat container.
I have developed a java servlet that monitors a folder on a network drive
How can I detect that the client side of a tomcat servlet request has
I'm developing a java servlet web application that manages information from multiple databases (all
This may be an incredibly stupid question, but I have a web application that
I have a servlet that I cannot change ( com.sun.jersey.spi.container.servlet.ServletContainer of Jersey RS) .
I have a server that has on it a servlet that functions as the

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.