You should return immediately with a status of 202 Accepted. Along with this, the HTTP spec agrees with Jonathan's answer:
The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.
You can set the status (in the servlet, for example) using:
response.setStatus(HttpServletResponse.SC_ACCEPTED);
Where response
is the HttpServletResponse
provided for the request.
Edit (re: comments):
Good browsers will treat any 2XX status as successful and will render the content provided in the response body to the user, so returning a 202 shouldn't affect web browser users and how they see pages. If the browser doesn't do this, it's probably violating Section 6.1.1 of the spec:
...applications MUST understand the class of any status code, as indicated by the first digit, and treat any unrecognized response as being equivalent to the x00 status code of that class...
Since a Tomcat server is just a specialized HTTP server, you should try to stick to the specification as much as possible (i.e. returning as appropriate a status as possible). Even if you intend your site to be accessed by a browser, there's nothing stopping other clients (curl, etc.) from requesting a page. If you provide specific statuses, clients can act more appropriately to responses.